From 4dfcfa63e71ace2453d374c3970300e32850b457 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 7 Dec 2021 14:42:19 +0000 Subject: [PATCH] [TurboModule] Setup the NDK Build for the Android app --- android/app/build.gradle | 36 +++++++++++++++++++++++++ android/app/src/main/jni/Android.mk | 41 +++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 android/app/src/main/jni/Android.mk diff --git a/android/app/build.gradle b/android/app/build.gradle index 641a2163..a1cbc78a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -145,7 +145,29 @@ android { targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" + + externalNativeBuild { + ndkBuild { + arguments "APP_PLATFORM=android-21", + "APP_STL=c++_shared", + "NDK_TOOLCHAIN_VERSION=clang", + "GENERATED_SRC_DIR=$buildDir/generated/source", + "PROJECT_BUILD_DIR=$buildDir", + "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", + "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build" + cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" + cppFlags "-std=c++17" + targets "rnnewarchitectureapp_appmodules" + } + } + } + + externalNativeBuild { + ndkBuild { + path "$projectDir/src/main/jni/Android.mk" + } } + splits { abi { reset() @@ -196,6 +218,20 @@ android { } } + def reactAndroidProjectDir = project(':ReactAndroid').projectDir + def packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) { + dependsOn(":ReactAndroid:packageReactNdkLibsForBuck") + dependsOn("generateCodegenArtifactsFromSchema") + from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") + into("$buildDir/react-ndk/exported") + } + + afterEvaluate { + preBuild.dependsOn(packageReactNdkLibs) + configureNdkBuildDebug.dependsOn(preBuild) + configureNdkBuildRelease.dependsOn(preBuild) + } + packagingOptions { pickFirst '**/libhermes.so' pickFirst '**/libjsc.so' diff --git a/android/app/src/main/jni/Android.mk b/android/app/src/main/jni/Android.mk new file mode 100644 index 00000000..74ad4c93 --- /dev/null +++ b/android/app/src/main/jni/Android.mk @@ -0,0 +1,41 @@ +THIS_DIR := $(call my-dir) + +include $(REACT_ANDROID_DIR)/Android-prebuilt.mk +include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk + +include $(CLEAR_VARS) + +LOCAL_PATH := $(THIS_DIR) +LOCAL_MODULE := rnnewarchitectureapp_appmodules + +LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni + +# Please note as one of the library listed is libreact_codegen_answersolver +# This name will be generated as libreact_codegen_ +# where is the one you specified in the Gradle configuration +LOCAL_SHARED_LIBRARIES := libjsi \ + libfbjni \ + libglog \ + libfolly_json \ + libyoga \ + libreact_nativemodule_core \ + libturbomodulejsijni \ + librrc_view \ + libreact_render_core \ + libreact_render_graphics \ + libfabricjni \ + libfolly_futures \ + libreact_debug \ + libreact_render_componentregistry \ + libreact_render_debug \ + libruntimeexecutor \ + libreact_codegen_rncore \ + react_codegen_answersolver + +LOCAL_CFLAGS := \ + -DLOG_TAG=\"ReactNative\" +LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall + +include $(BUILD_SHARED_LIBRARY) \ No newline at end of file