Skip to content

Commit

Permalink
TurboModule Android: properly set up RNTester ndkBuild and cleanup de…
Browse files Browse the repository at this point in the history
…pendencies

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
  • Loading branch information
fkgozali authored and facebook-github-bot committed Sep 30, 2020
1 parent ca51dc6 commit b931bd3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ReactAndroid/Android-prebuilt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
83 changes: 56 additions & 27 deletions packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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)
}
}

0 comments on commit b931bd3

Please sign in to comment.