Skip to content

Commit abff021

Browse files
fkgozalifacebook-github-bot
authored andcommitted
TurboModule Android: compile codegen C++ output into librntester_appmodules.so
Summary: The react-native-codegen provides Android.mk in the Android C++ output, but for RNTester (or hosting apps), we should just compile the codegen output with the rest of the app-specific C++ files. This is to simplify the build configuration, and also to not add too many additional .so libs to the APK. With this commit, `RNTesterAppModuleProvider.cpp` should be "complete" for RNTester use-case. This TurboModule lookup function is the one described in react-native-community/discussions-and-proposals#273. Changelog: [Internal] Reviewed By: hramos Differential Revision: D23913149 fbshipit-source-id: d1ca136787b87a0e8e6504318e1f0a78efef46ea
1 parent 9f00752 commit abff021

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/rn-tester/android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ if (enableCodegen) {
198198
"NDK_TOOLCHAIN_VERSION=clang",
199199
// The following paths assume building React Native from source.
200200
// TODO: Find a better way without pointing to ReactAndroid/build dir.
201+
"GENERATED_SRC_DIR=$buildDir/generated/source",
201202
"REACT_ANDROID_SRC_DIR=$reactAndroidProjectDir/src/main",
202203
"REACT_COMMON_DIR=$rootDir/ReactCommon",
203204
"REACT_GENERATED_SRC_DIR=$reactAndroidBuildDir/generated/source",

packages/rn-tester/android/app/src/main/jni/Android.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ include $(PREBUILT_SHARED_LIBRARY)
6060

6161
include $(CLEAR_VARS)
6262
LOCAL_MODULE := rntester_appmodules
63-
LOCAL_C_INCLUDES := $(LOCAL_PATH)
64-
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
65-
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
63+
# Note: Build the react-native-codegen output along with other app-specific C++ files.
64+
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
65+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
66+
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
6667
LOCAL_SHARED_LIBRARIES := libreact_nativemodule_core libreact_nativemodule_manager libreact_codegen_reactandroidspec
6768
LOCAL_CFLAGS := \
6869
-DLOG_TAG=\"ReactNative\"

packages/rn-tester/android/app/src/main/jni/RNTesterAppModuleProvider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
#include "RNTesterAppModuleProvider.h"
99

10+
#include <PackagesRnTesterAndroidAppSpec.h>
1011
#include <ReactAndroidSpec.h>
1112

1213
namespace facebook {
1314
namespace react {
1415

1516
std::shared_ptr<TurboModule> RNTesterAppModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
17+
auto module = PackagesRnTesterAndroidAppSpec_ModuleProvider(moduleName, params);
18+
if (module != nullptr) {
19+
return module;
20+
}
1621
return ReactAndroidSpec_ModuleProvider(moduleName, params);
1722
}
1823

0 commit comments

Comments
 (0)