From 0d42f099f0108b07bcc15ed3571ba60cea3a38f8 Mon Sep 17 00:00:00 2001 From: Agastya Darma Date: Sat, 19 Sep 2020 21:22:57 +0700 Subject: [PATCH 1/4] feat: add an explicit NDK version to gradle --- ReactAndroid/build.gradle | 4 ++-- packages/rn-tester/android/app/build.gradle | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 1189ead6e9a4c4..496f02bc926fcd 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -380,7 +380,7 @@ task extractJNIFiles { android { compileSdkVersion 29 - + ndkVersion ndkVersion compileOptions { sourceCompatibility(JavaVersion.VERSION_1_8) targetCompatibility(JavaVersion.VERSION_1_8) @@ -391,7 +391,7 @@ android { targetSdkVersion(28) versionCode(1) versionName("1.0") - + ndkVersion "20.1.5948944" consumerProguardFiles("proguard-rules.pro") buildConfigField("boolean", "IS_INTERNAL_BUILD", "false") diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 3bad38b8dc353f..06855c064acd05 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -121,7 +121,7 @@ def useIntlJsc = false android { compileSdkVersion 29 - + ndkVersion ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -142,6 +142,7 @@ android { defaultConfig { applicationId "com.facebook.react.uiapp" minSdkVersion 19 + ndkVersion "20.1.5948944" targetSdkVersion 29 versionCode 1 versionName "1.0" From a2a1dd4ff6bee230603f362458f44344c01e8b1a Mon Sep 17 00:00:00 2001 From: Agastya Darma Date: Tue, 22 Sep 2020 23:13:37 +0700 Subject: [PATCH 2/4] refactor: findNdkBuildFullPath ndkDir --- ReactAndroid/build.gradle | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 496f02bc926fcd..e0c53aaa99174d 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -247,25 +247,11 @@ def getNdkBuildName() { } def findNdkBuildFullPath() { - // we allow to provide full path to ndk-build tool - if (hasProperty("ndk.command")) { - return property("ndk.command") - } - // or just a path to the containing directory - if (hasProperty("ndk.path")) { - def ndkDir = property("ndk.path") - return new File(ndkDir, getNdkBuildName()).getAbsolutePath() - } - - if (System.getenv("ANDROID_NDK") != null) { - def ndkDir = System.getenv("ANDROID_NDK") - return new File(ndkDir, getNdkBuildName()).getAbsolutePath() - } - - def ndkDir = android.ndkDirectory ? android.ndkDirectory.absolutePath : null - - if (ndkDir) { - return new File(ndkDir, getNdkBuildName()).getAbsolutePath() + if (System.getenv("ANDROID_HOME") != null) { + def sdkDir = System.getenv("ANDROID_HOME") + def ndkDir = new File(sdkDir, "ndk").getAbsolutePath() + def ndkVersionedDir = new File(ndkDir, project.android.ndkVersion).getAbsolutePath() + return new File(ndkVersionedDir, getNdkBuildName()).getAbsolutePath() } return null } @@ -285,15 +271,14 @@ def getNdkBuildFullPath() { if (ndkBuildFullPath == null) { throw new GradleScriptException( "ndk-build binary cannot be found, check if you've set " + - "\$ANDROID_NDK environment variable correctly or if ndk.dir is " + - "setup in local.properties", + "\$ANDROID_HOME environment variable correctly and you have installed the correct NDK version (" + + project.android.ndkVersion + ")", null) } if (!new File(ndkBuildFullPath).canExecute()) { throw new GradleScriptException( "ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" + - "Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.properties, is set correctly.\n" + - "(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)", + "Check that you have installed the correct NDK version (" + project.android.ndkVersion + ")", null) } return ndkBuildFullPath @@ -392,6 +377,7 @@ android { versionCode(1) versionName("1.0") ndkVersion "20.1.5948944" + consumerProguardFiles("proguard-rules.pro") buildConfigField("boolean", "IS_INTERNAL_BUILD", "false") From 7c210d0c7da3d234958bdb05c2187608842f833d Mon Sep 17 00:00:00 2001 From: Agastya Darma Date: Wed, 23 Sep 2020 18:28:54 +0700 Subject: [PATCH 3/4] refactor: ndkDirectory --- ReactAndroid/build.gradle | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index e0c53aaa99174d..0a750ab2fc3118 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -247,12 +247,28 @@ def getNdkBuildName() { } def findNdkBuildFullPath() { - if (System.getenv("ANDROID_HOME") != null) { - def sdkDir = System.getenv("ANDROID_HOME") - def ndkDir = new File(sdkDir, "ndk").getAbsolutePath() - def ndkVersionedDir = new File(ndkDir, project.android.ndkVersion).getAbsolutePath() - return new File(ndkVersionedDir, getNdkBuildName()).getAbsolutePath() + // android.ndkDirectory should return project.android.ndkVersion ndkDirectory + def ndkDir = android.ndkDirectory ? android.ndkDirectory.absolutePath : null + if (ndkDir) { + return new File(ndkDir, getNdkBuildName()).getAbsolutePath() } + + // we allow to provide full path to ndk-build tool + if (hasProperty("ndk.command")) { + return property("ndk.command") + } + // or just a path to the containing directory + if (hasProperty("ndk.path")) { + ndkDir = property("ndk.path") + return new File(ndkDir, getNdkBuildName()).getAbsolutePath() + } + + // @TODO ANDROID_NDK && ndk.dir is deprecated and will be removed in the future. + if (System.getenv("ANDROID_NDK") != null) { + ndkDir = System.getenv("ANDROID_NDK") + return new File(ndkDir, getNdkBuildName()).getAbsolutePath() + } + return null } @@ -271,14 +287,15 @@ def getNdkBuildFullPath() { if (ndkBuildFullPath == null) { throw new GradleScriptException( "ndk-build binary cannot be found, check if you've set " + - "\$ANDROID_HOME environment variable correctly and you have installed the correct NDK version (" + - project.android.ndkVersion + ")", + "\$ANDROID_NDK environment variable correctly or if ndk.dir is " + + "setup in local.properties", null) } if (!new File(ndkBuildFullPath).canExecute()) { throw new GradleScriptException( "ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" + - "Check that you have installed the correct NDK version (" + project.android.ndkVersion + ")", + "Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.properties, is set correctly.\n" + + "(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)", null) } return ndkBuildFullPath From 819452b8b5566956f217b4fa1c4d04ac83049e96 Mon Sep 17 00:00:00 2001 From: Agastya Darma Date: Thu, 24 Sep 2020 11:40:15 +0700 Subject: [PATCH 4/4] refactor: put ndkVersion directly under Android --- ReactAndroid/build.gradle | 3 +-- packages/rn-tester/android/app/build.gradle | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 0a750ab2fc3118..4b3dbace1883bb 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -382,7 +382,7 @@ task extractJNIFiles { android { compileSdkVersion 29 - ndkVersion ndkVersion + ndkVersion "20.1.5948944" compileOptions { sourceCompatibility(JavaVersion.VERSION_1_8) targetCompatibility(JavaVersion.VERSION_1_8) @@ -393,7 +393,6 @@ android { targetSdkVersion(28) versionCode(1) versionName("1.0") - ndkVersion "20.1.5948944" consumerProguardFiles("proguard-rules.pro") diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 06855c064acd05..e7f38e4e797f3c 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -121,7 +121,7 @@ def useIntlJsc = false android { compileSdkVersion 29 - ndkVersion ndkVersion + ndkVersion "20.1.5948944" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -142,7 +142,6 @@ android { defaultConfig { applicationId "com.facebook.react.uiapp" minSdkVersion 19 - ndkVersion "20.1.5948944" targetSdkVersion 29 versionCode 1 versionName "1.0"