Skip to content

Commit 4dfcfa6

Browse files
committed
[TurboModule] Setup the NDK Build for the Android app
1 parent a0cf888 commit 4dfcfa6

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

android/app/build.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,29 @@ android {
145145
targetSdkVersion rootProject.ext.targetSdkVersion
146146
versionCode 1
147147
versionName "1.0"
148+
149+
externalNativeBuild {
150+
ndkBuild {
151+
arguments "APP_PLATFORM=android-21",
152+
"APP_STL=c++_shared",
153+
"NDK_TOOLCHAIN_VERSION=clang",
154+
"GENERATED_SRC_DIR=$buildDir/generated/source",
155+
"PROJECT_BUILD_DIR=$buildDir",
156+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
157+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
158+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
159+
cppFlags "-std=c++17"
160+
targets "rnnewarchitectureapp_appmodules"
161+
}
162+
}
163+
}
164+
165+
externalNativeBuild {
166+
ndkBuild {
167+
path "$projectDir/src/main/jni/Android.mk"
168+
}
148169
}
170+
149171
splits {
150172
abi {
151173
reset()
@@ -196,6 +218,20 @@ android {
196218
}
197219
}
198220

221+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
222+
def packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) {
223+
dependsOn(":ReactAndroid:packageReactNdkLibsForBuck")
224+
dependsOn("generateCodegenArtifactsFromSchema")
225+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
226+
into("$buildDir/react-ndk/exported")
227+
}
228+
229+
afterEvaluate {
230+
preBuild.dependsOn(packageReactNdkLibs)
231+
configureNdkBuildDebug.dependsOn(preBuild)
232+
configureNdkBuildRelease.dependsOn(preBuild)
233+
}
234+
199235
packagingOptions {
200236
pickFirst '**/libhermes.so'
201237
pickFirst '**/libjsc.so'

android/app/src/main/jni/Android.mk

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
THIS_DIR := $(call my-dir)
2+
3+
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4+
include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
5+
6+
include $(CLEAR_VARS)
7+
8+
LOCAL_PATH := $(THIS_DIR)
9+
LOCAL_MODULE := rnnewarchitectureapp_appmodules
10+
11+
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
12+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
13+
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
14+
15+
# Please note as one of the library listed is libreact_codegen_answersolver
16+
# This name will be generated as libreact_codegen_<library-name>
17+
# where <library-name> is the one you specified in the Gradle configuration
18+
LOCAL_SHARED_LIBRARIES := libjsi \
19+
libfbjni \
20+
libglog \
21+
libfolly_json \
22+
libyoga \
23+
libreact_nativemodule_core \
24+
libturbomodulejsijni \
25+
librrc_view \
26+
libreact_render_core \
27+
libreact_render_graphics \
28+
libfabricjni \
29+
libfolly_futures \
30+
libreact_debug \
31+
libreact_render_componentregistry \
32+
libreact_render_debug \
33+
libruntimeexecutor \
34+
libreact_codegen_rncore \
35+
react_codegen_answersolver
36+
37+
LOCAL_CFLAGS := \
38+
-DLOG_TAG=\"ReactNative\"
39+
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
40+
41+
include $(BUILD_SHARED_LIBRARY)

0 commit comments

Comments
 (0)