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 https://github.com/react-native-community/discussions-and-proposals/issues/273.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23913149

fbshipit-source-id: d1ca136787b87a0e8e6504318e1f0a78efef46ea
This commit is contained in:
Kevin Gozali
2020-09-24 15:21:39 -07:00
committed by Facebook GitHub Bot
parent 9f00752a97
commit abff021261
3 changed files with 10 additions and 3 deletions
@@ -198,6 +198,7 @@ if (enableCodegen) {
"NDK_TOOLCHAIN_VERSION=clang",
// The following paths assume building React Native from source.
// TODO: Find a better way without pointing to ReactAndroid/build dir.
"GENERATED_SRC_DIR=$buildDir/generated/source",
"REACT_ANDROID_SRC_DIR=$reactAndroidProjectDir/src/main",
"REACT_COMMON_DIR=$rootDir/ReactCommon",
"REACT_GENERATED_SRC_DIR=$reactAndroidBuildDir/generated/source",
@@ -60,9 +60,10 @@ include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := rntester_appmodules
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
# Note: Build the react-native-codegen output along with other app-specific C++ files.
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
LOCAL_SHARED_LIBRARIES := libreact_nativemodule_core libreact_nativemodule_manager libreact_codegen_reactandroidspec
LOCAL_CFLAGS := \
-DLOG_TAG=\"ReactNative\"
@@ -7,12 +7,17 @@
#include "RNTesterAppModuleProvider.h"
#include <PackagesRnTesterAndroidAppSpec.h>
#include <ReactAndroidSpec.h>
namespace facebook {
namespace react {
std::shared_ptr<TurboModule> RNTesterAppModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
auto module = PackagesRnTesterAndroidAppSpec_ModuleProvider(moduleName, params);
if (module != nullptr) {
return module;
}
return ReactAndroidSpec_ModuleProvider(moduleName, params);
}