mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
TurboModule Android: properly set up RNTester ndkBuild and cleanup dependencies
Summary: Before RNTester compilation starts, it needs to wait for :ReactAndroid NDK build to finish, so that it knows where to find the exported .so files. This tells the `preBuild` task to depends on `:ReactAndroid:prepareReactNdkLibs` task. The .so files are now copied over to the local project build dir, instead of depending on :ReactAndroid's build dir. For cleanup, the reverse ordering is needed: before `clean` removed our temp dir to store the copied .so files, make sure the ndkBuild cleanup tasks execute beforehand. Changelog: [Internal] Reviewed By: hramos Differential Revision: D23982989 fbshipit-source-id: 955d7c9bccb5855b6b066fca89764df2ede89f63
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ca51dc6288
commit
b931bd33fe
@@ -24,7 +24,7 @@ REACT_ANDROID_SRC_DIR := $(REACT_ANDROID_DIR)/src/main
|
||||
REACT_COMMON_DIR := $(REACT_ANDROID_DIR)/../ReactCommon
|
||||
REACT_GENERATED_SRC_DIR := $(REACT_ANDROID_BUILD_DIR)/generated/source
|
||||
# Note: this only have .so, not .a
|
||||
REACT_NDK_EXPORT_DIR := $(REACT_ANDROID_BUILD_DIR)/react-ndk/exported
|
||||
REACT_NDK_EXPORT_DIR := $(PROJECT_BUILD_DIR)/react-ndk/exported
|
||||
|
||||
# fb
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
@@ -186,33 +186,6 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
if (enableCodegen) {
|
||||
def reactAndroidProjectDir = project(':ReactAndroid').projectDir;
|
||||
android {
|
||||
defaultConfig {
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
|
||||
arguments "APP_PLATFORM=android-16",
|
||||
"APP_STL=c++_shared",
|
||||
"NDK_TOOLCHAIN_VERSION=clang",
|
||||
// The following paths assume building React Native from source.
|
||||
"GENERATED_SRC_DIR=$buildDir/generated/source",
|
||||
"REACT_ANDROID_DIR=$reactAndroidProjectDir"
|
||||
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
|
||||
cppFlags "-std=c++1y"
|
||||
targets "rntester_appmodules"
|
||||
}
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path "$projectDir/src/main/jni/Android.mk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
hermesDebugImplementation {}
|
||||
hermesReleaseImplementation {}
|
||||
@@ -258,3 +231,59 @@ react {
|
||||
reactNativeRootDir = file("$rootDir")
|
||||
useJavaGenerator = System.getenv("USE_CODEGEN_JAVAPOET") ?: false
|
||||
}
|
||||
|
||||
if (enableCodegen) {
|
||||
// TODO: Move all this logic to CodegenPlugin.java.
|
||||
def reactAndroidProjectDir = project(':ReactAndroid').projectDir;
|
||||
def reactAndroidBuildDir = project(':ReactAndroid').buildDir;
|
||||
|
||||
android {
|
||||
defaultConfig {
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
|
||||
arguments "APP_PLATFORM=android-16",
|
||||
"APP_STL=c++_shared",
|
||||
"NDK_TOOLCHAIN_VERSION=clang",
|
||||
// The following paths assume building React Native from source.
|
||||
"GENERATED_SRC_DIR=$buildDir/generated/source",
|
||||
"PROJECT_BUILD_DIR=$buildDir",
|
||||
"REACT_ANDROID_DIR=$reactAndroidProjectDir"
|
||||
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
|
||||
cppFlags "-std=c++1y"
|
||||
targets "rntester_appmodules"
|
||||
}
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path "$projectDir/src/main/jni/Android.mk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) {
|
||||
// TODO: handle extracting .so from prebuilt :ReactAndroid.
|
||||
dependsOn(":ReactAndroid:packageReactNdkLibs")
|
||||
from("$reactAndroidBuildDir/react-ndk/exported")
|
||||
into("$buildDir/react-ndk/exported")
|
||||
}
|
||||
|
||||
def cleanProjectNdkBuild = tasks.register("cleanProjectNdkBuild", Exec) {
|
||||
ignoreExitValue(true)
|
||||
tasks.forEach {
|
||||
t ->
|
||||
if (t.name.startsWith("externalNativeBuildClean")) {
|
||||
dependsOn(t);
|
||||
}
|
||||
}
|
||||
// This .cxx folder may cause stale ndkBuild configuration.
|
||||
// See https://stackoverflow.com/a/58288851.
|
||||
commandLine("rm", "-rf", "$projectDir/.cxx")
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
preBuild.dependsOn(packageReactNdkLibs)
|
||||
clean.dependsOn(cleanProjectNdkBuild)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user