Create multiple Cxx TurboModules in same package #283
-
Hi! I have a npm package with multiple cross-platform C++ modules, but on android, the second one fails to link. My structure:
react-native.config.js: module.exports = {
dependency: {
platforms: {
android: {
cxxModuleCMakeListsModuleName: 'A',
cxxModuleCMakeListsPath: 'CMakeLists.txt',
cxxModuleHeaderName: 'NativeATurboModule',
},
},
},
}; I think as NativeATurboModule is defined as cxxModuleHeaderName, that's the reason only the A module is linked? When I check the the autolinking.cpp, I can find this line: std::shared_ptr<TurboModule> autolinking_cxxModuleProvider(const std::string moduleName, const std::shared_ptr<CallInvoker>& jsInvoker) {
if (moduleName == NativeATurboModule::kModuleName) {
return std::make_shared<NativeATurboModule>(jsInvoker);
}
return nullptr;
} But in the locally generated codegen folder of the package, I can also find this one (inside the RNModuleNameSpec-generated.cpp): std::shared_ptr<TurboModule> RNMultiTrackPlayerSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
if (moduleName == "A") {
return std::make_shared<NativeASpecJSI>(params);
}
if (moduleName == "B") {
return std::make_shared<NativeBSpecJSI>(params);
}
return nullptr;
} Does anyone know how to add multiple C++ TurboModules in an npm package? I think I can merge all the definitions, but this would result in a really large and kinda messy module... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is sadly not supported at the moment. As we need to generate a lot of C++ code for this to work, the initial implementation of Autolinking for pure C++ TM, was done under the assumption that there would be one module per NPM package. You should create a separate package for The |
Beta Was this translation helpful? Give feedback.
-
hey, @cortinico Writing native modules with C++ is only available from React Native version 0.76? |
Beta Was this translation helpful? Give feedback.
This is sadly not supported at the moment. As we need to generate a lot of C++ code for this to work, the initial implementation of Autolinking for pure C++ TM, was done under the assumption that there would be one module per NPM package.
You should create a separate package for
NativeA
andNativeB
as they will generate separate module provider and need to be both autolinked.The
react-native.config.js
file also allows for a single module and not an array of them.