Skip to content

Commit

Permalink
TurboModule Android: compile codegen C++ output into librntester_appm…
Browse files Browse the repository at this point in the history
…odules.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
  • Loading branch information
fkgozali authored and facebook-github-bot committed Sep 24, 2020
1 parent 9f00752 commit abff021
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions packages/rn-tester/android/app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit abff021

Please sign in to comment.