fix: Fix Android tasks execution (#407)

This commit is contained in:
Natalia 2021-09-06 10:32:06 +02:00 committed by GitHub
parent 98128471cc
commit 3b7560ac4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 60 deletions

View File

@ -241,33 +241,6 @@ dependencies {
implementation "androidx.exifinterface:exifinterface:1.3.3" 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 // third-party-ndk deps headers
// mostly a copy of https://github.com/software-mansion/react-native-reanimated/blob/master/android/build.gradle#L115 // 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") def glog_file = new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz")
task createNativeDepsDirectories { task createNativeDepsDirectories {
downloadsDir.mkdirs() doLast {
thirdPartyNdkDir.mkdirs() downloadsDir.mkdirs()
thirdPartyNdkDir.mkdirs()
}
} }
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) { task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
@ -384,26 +359,47 @@ task prepareGlog(dependsOn: downloadGlog, type: Copy) {
} }
} }
task prepareHermes() { task prepareThirdPartyNdkHeaders {
def hermesPackagePath = findNodeModulePath(projectDir, "hermes-engine") if (!boost_file.exists()) {
if (!hermesPackagePath) { dependsOn(prepareBoost)
throw new GradleScriptException("Could not find the hermes-engine npm package", null)
} }
if (!double_conversion_file.exists()) {
def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar") dependsOn(prepareDoubleConversion)
if (!hermesAAR.exists()) {
throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
} }
if (!folly_file.exists()) {
def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" }) dependsOn(prepareFolly)
}
copy { if (!glog_file.exists()) {
from soFiles dependsOn(prepareGlog)
from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
into "$thirdPartyNdkDir/hermes"
} }
} }
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 { task prepareJSC {
doLast { doLast {
def jscPackagePath = findNodeModulePath(projectDir, "jsc-android") def jscPackagePath = findNodeModulePath(projectDir, "jsc-android")
@ -434,29 +430,47 @@ task prepareJSC {
} }
} }
task prepareThirdPartyNdkHeaders { prepareJSC.mustRunAfter prepareHermes
if (!boost_file.exists()) {
dependsOn(prepareBoost) task extractAARHeaders {
} doLast {
if (!double_conversion_file.exists()) { configurations.extractHeaders.files.each {
dependsOn(prepareDoubleConversion) def file = it.absoluteFile
} copy {
if (!folly_file.exists()) { from zipTree(file)
dependsOn(prepareFolly) into "$buildDir/$file.name"
} include "**/*.h"
if (!glog_file.exists()) { }
dependsOn(prepareGlog) }
} }
} }
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 // pre-native build pipeline
tasks.whenTaskAdded { task -> tasks.whenTaskAdded { task ->
if (task.name.contains('externalNativeBuild')) { if (task.name == 'externalNativeBuildDebug' || task.name == 'externalNativeBuildRelease') {
task.dependsOn(prepareJSC)
task.dependsOn(prepareHermes)
task.dependsOn(extractAARHeaders) task.dependsOn(extractAARHeaders)
task.dependsOn(extractJNIFiles) task.dependsOn(extractJNIFiles)
task.dependsOn(prepareJSC)
task.dependsOn(prepareHermes)
task.dependsOn(prepareThirdPartyNdkHeaders) task.dependsOn(prepareThirdPartyNdkHeaders)
} }
} }

View File

@ -10,7 +10,7 @@
# Specifies the JVM arguments used for the daemon process. # Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings. # The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m # 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. # When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit