Skip to content

Commit b6555e4

Browse files
RSNarafacebook-github-bot
authored andcommitted
Remove core modules from the default tmmdelegate (#43939)
Summary: Pull Request resolved: #43939 ## Problem If we link the default tmmdelegate with our vr apps, we get this issue: ``` ld.lld: error: duplicate symbol: facebook::react::NativeDevLoadingViewSpecJSI::NativeDevLoadingViewSpecJSI(facebook::react::JavaTurboModule::InitParams const&) >>> defined at firsttimenux_v2AppModulesCodegen-generated.cpp:1367 (buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/arvr/libraries/react-panellib/FirstTimeNux/__firsttimenux_v2AppModulesCodegen-codegen-modules-jni_cpp__/out/firsttimenux_v2AppModulesCodegen-generated.cpp:1367) >>> firsttimenux_v2AppModulesCodegen-generated.cpp.pic.o:(facebook::react::NativeDevLoadingViewSpecJSI::NativeDevLoadingViewSpecJSI(facebook::react::JavaTurboModule::InitParams const&)) in archive buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/arvr/libraries/react-panellib/FirstTimeNux/__firsttimenux_v2AppModulesCodegen-jni__/libfirsttimenux_v2AppModulesCodegen-jni.pic.a >>> defined at rncore-generated.cpp:606 (buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/xplat/js/react-native-github/__rncore-codegen-modules-jni_cpp__/out/rncore-generated.cpp:606) >>> rncore-generated.cpp.pic.o:(.text._ZN8facebook5react27NativeDevLoadingViewSpecJSIC2ERKNS0_15JavaTurboModule10InitParamsE+0x0) in archive buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/xplat/js/react-native-github/__rncore-jniAndroid__/librncore-jniAndroid.pic.a ``` ## Cause My best understanding of the problem: - Default tmmdelegate links against rncore, which contains codegen for react native's standard library of modules. - But, the default delegate also pulls in this appmodules.so library. That library also contains codegen for react native's standard library of modules + the app's modules. So, two so libraries define the same symbols. Hence the build fails. ## Solution Remove the codegen for react native's standard library of modules from the default tmmdelegate. Prereq: In open source, also make appmodules.so include the codegen for react native's standard library of modules. Changelog: [Android][Breaking] - Make the app responsible for returning core turbomodule jsi hostobjects Reviewed By: cortinico Differential Revision: D55613024
1 parent 1fc9c56 commit b6555e4

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <fbjni/fbjni.h>
3333
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
3434
#include <rncli.h>
35+
#include <rncore.h>
3536

3637
#ifdef REACT_NATIVE_APP_CODEGEN_HEADER
3738
#include REACT_NATIVE_APP_CODEGEN_HEADER
@@ -95,8 +96,17 @@ std::shared_ptr<TurboModule> javaModuleProvider(
9596
}
9697
#endif
9798

99+
// We first try to look up core modules
100+
if (auto module = rncore_ModuleProvider(name, params)) {
101+
return module;
102+
}
103+
98104
// And we fallback to the module providers autolinked by RN CLI
99-
return rncli_ModuleProvider(name, params);
105+
if (auto module = rncli_ModuleProvider(name, params)) {
106+
return module;
107+
}
108+
109+
return nullptr;
100110
}
101111

102112
} // namespace facebook::react

packages/react-native/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <react/nativemodule/dom/NativeDOM.h>
1313
#include <react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h>
1414
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
15-
#include <rncore.h>
1615

1716
namespace facebook::react {
1817

@@ -100,7 +99,8 @@ std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule(
10099
return resolvedModule;
101100
}
102101
}
103-
return rncore_ModuleProvider(name, params);
102+
103+
return nullptr;
104104
}
105105

106106
} // namespace facebook::react

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ReactCommon/SampleTurboModuleSpec.h>
1212
#include <fbjni/fbjni.h>
1313
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
14+
#include <rncore.h>
1415

1516
#ifdef REACT_NATIVE_APP_CODEGEN_HEADER
1617
#include REACT_NATIVE_APP_CODEGEN_HEADER
@@ -51,6 +52,12 @@ std::shared_ptr<TurboModule> javaModuleProvider(
5152
return module;
5253
}
5354
#endif
55+
56+
// We first try to look up core modules
57+
if (auto module = rncore_ModuleProvider(name, params)) {
58+
return module;
59+
}
60+
5461
return nullptr;
5562
}
5663

0 commit comments

Comments
 (0)