From 3b7560ac4d09d57e515ccc07f4740abc8f1bed8a Mon Sep 17 00:00:00 2001 From: Natalia Date: Mon, 6 Sep 2021 10:32:06 +0200 Subject: [PATCH] fix: Fix Android tasks execution (#407) --- android/build.gradle | 132 +++++++++++++++++------------- example/android/gradle.properties | 2 +- 2 files changed, 74 insertions(+), 60 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c7efd7a..edebe2e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -241,33 +241,6 @@ dependencies { implementation "androidx.exifinterface:exifinterface:1.3.3" } -task extractAARHeaders { - doLast { - configurations.extractHeaders.files.each { - def file = it.absoluteFile - copy { - from zipTree(file) - into "$buildDir/$file.name" - include "**/*.h" - } - } - } -} - -task extractJNIFiles { - doLast { - configurations.extractJNI.files.each { - def file = it.absoluteFile - - copy { - from zipTree(file) - into "$buildDir/$file.name" - include "jni/**/*" - } - } - } -} - // third-party-ndk deps headers // mostly a copy of https://github.com/software-mansion/react-native-reanimated/blob/master/android/build.gradle#L115 @@ -287,8 +260,10 @@ def GLOG_VERSION = thirdPartyVersions["GLOG_VERSION"] def glog_file = new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz") task createNativeDepsDirectories { - downloadsDir.mkdirs() - thirdPartyNdkDir.mkdirs() + doLast { + downloadsDir.mkdirs() + thirdPartyNdkDir.mkdirs() + } } task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) { @@ -384,26 +359,47 @@ task prepareGlog(dependsOn: downloadGlog, type: Copy) { } } -task prepareHermes() { - def hermesPackagePath = findNodeModulePath(projectDir, "hermes-engine") - if (!hermesPackagePath) { - throw new GradleScriptException("Could not find the hermes-engine npm package", null) +task prepareThirdPartyNdkHeaders { + if (!boost_file.exists()) { + dependsOn(prepareBoost) } - - def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar") - if (!hermesAAR.exists()) { - throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null) + if (!double_conversion_file.exists()) { + dependsOn(prepareDoubleConversion) } - - def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" }) - - copy { - from soFiles - from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk" - into "$thirdPartyNdkDir/hermes" + if (!folly_file.exists()) { + dependsOn(prepareFolly) + } + if (!glog_file.exists()) { + dependsOn(prepareGlog) } } +prepareThirdPartyNdkHeaders.mustRunAfter createNativeDepsDirectories + +task prepareHermes() { + doLast { + def hermesPackagePath = findNodeModulePath(projectDir, "hermes-engine") + if (!hermesPackagePath) { + throw new GradleScriptException("Could not find the hermes-engine npm package", null) + } + + def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar") + if (!hermesAAR.exists()) { + throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null) + } + + def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" }) + + copy { + from soFiles + from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk" + into "$thirdPartyNdkDir/hermes" + } + } +} + +prepareHermes.mustRunAfter prepareThirdPartyNdkHeaders + task prepareJSC { doLast { def jscPackagePath = findNodeModulePath(projectDir, "jsc-android") @@ -434,29 +430,47 @@ task prepareJSC { } } -task prepareThirdPartyNdkHeaders { - if (!boost_file.exists()) { - dependsOn(prepareBoost) - } - if (!double_conversion_file.exists()) { - dependsOn(prepareDoubleConversion) - } - if (!folly_file.exists()) { - dependsOn(prepareFolly) - } - if (!glog_file.exists()) { - dependsOn(prepareGlog) +prepareJSC.mustRunAfter prepareHermes + +task extractAARHeaders { + doLast { + configurations.extractHeaders.files.each { + def file = it.absoluteFile + copy { + from zipTree(file) + into "$buildDir/$file.name" + include "**/*.h" + } + } } } +extractAARHeaders.mustRunAfter prepareJSC + +task extractJNIFiles { + doLast { + configurations.extractJNI.files.each { + def file = it.absoluteFile + + copy { + from zipTree(file) + into "$buildDir/$file.name" + include "jni/**/*" + } + } + } +} + +extractJNIFiles.mustRunAfter extractAARHeaders + // pre-native build pipeline tasks.whenTaskAdded { task -> - if (task.name.contains('externalNativeBuild')) { - task.dependsOn(prepareJSC) - task.dependsOn(prepareHermes) + if (task.name == 'externalNativeBuildDebug' || task.name == 'externalNativeBuildRelease') { task.dependsOn(extractAARHeaders) task.dependsOn(extractJNIFiles) + task.dependsOn(prepareJSC) + task.dependsOn(prepareHermes) task.dependsOn(prepareThirdPartyNdkHeaders) } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 027ef9d..c62d03d 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit