From 7c8e266e390de71ce39233b53a369b2c5e8a1c14 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Wed, 18 Sep 2019 02:32:52 -0700 Subject: [PATCH] lazy configure ReactAndroid gradle tasks (#26314) Summary: ReactAndroid Gradle was failing mysteriously with error below, because it was trying to read values from **android** when it wasn't configured completely. ```java extensionSupplier.get()!!.compileSdkVersion must not be null ``` or ```java compileSdkVersion is not specified. ``` It is happening because **buildReactNdkLib** task was created and configured eagerly. So this PR changes some tasks to be configured lazily, and reads values from **android** when ready. Also remove ANDROID_NDK variable check because android gradle plugin doing it automatically. ## Changelog [Android] [Changed] - lazily configure ReactAndroid gradle tasks Pull Request resolved: https://github.com/facebook/react-native/pull/26314 Test Plan: ./gradlew ReactAndroid:tasks run without errors, while master throws exception. Differential Revision: D17177945 Pulled By: cpojer fbshipit-source-id: c7a165092157d2059f946da70b801d1a475d4b8c --- ReactAndroid/build.gradle | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 67948d706c4565..0966bc4a41e92b 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -210,14 +210,14 @@ def findNdkBuildFullPath() { 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.hasProperty("plugin") ? android.plugin.ndkFolder : - plugins.getPlugin("com.android.library").hasProperty("sdkHandler") ? - plugins.getPlugin("com.android.library").sdkHandler.getNdkFolder() : - android.ndkDirectory ? android.ndkDirectory.absolutePath : null + + def ndkDir = android.ndkDirectory ? android.ndkDirectory.absolutePath : null + if (ndkDir) { return new File(ndkDir, getNdkBuildName()).getAbsolutePath() } @@ -253,7 +253,8 @@ def getNdkBuildFullPath() { return ndkBuildFullPath } -task buildReactNdkLib(dependsOn: [prepareJSC, prepareHermes, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) { +def buildReactNdkLib = tasks.register("buildReactNdkLib", Exec) { + dependsOn(prepareJSC, prepareHermes, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog) inputs.dir("$projectDir/../ReactCommon") inputs.dir("src/main/jni") outputs.dir("$buildDir/react-ndk/all") @@ -271,7 +272,7 @@ task buildReactNdkLib(dependsOn: [prepareJSC, prepareHermes, prepareBoost, prepa ) } -task cleanReactNdkLib(type: Exec) { +def cleanReactNdkLib = tasks.register("cleanReactNdkLib", Exec) { ignoreExitValue(true) errorOutput(new ByteArrayOutputStream()) commandLine(getNdkBuildFullPath(), @@ -286,14 +287,16 @@ task cleanReactNdkLib(type: Exec) { } } -task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) { +def packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) { + dependsOn(buildReactNdkLib) from("$buildDir/react-ndk/all") into("$buildDir/react-ndk/exported") exclude("**/libjsc.so") exclude("**/libhermes.so") } -task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) { +def packageReactNdkLibsForBuck = tasks.register("packageReactNdkLibsForBuck", Copy) { + dependsOn(packageReactNdkLibs) from("$buildDir/react-ndk/exported") into("src/main/jni/prebuilt/lib") }