Skip to content

Commit c1a56a7

Browse files
authored
fix(android): always include ReactNative-application.cmake on 0.76 (#2310)
1 parent 2cf1350 commit c1a56a7

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

android/app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ android {
125125
resValue "string", "app_name", project.ext.react.appName
126126

127127
def cppStd = reactNativeVersion >= v(0, 74, 0) ? "-std=c++20" : "-std=c++17"
128-
if (enableNewArchitecture) {
128+
if (reactNativeVersion >= v(0, 76, 0) || enableNewArchitecture) {
129129
externalNativeBuild {
130130
cmake {
131131
arguments "-DANDROID_STL=c++_shared",

android/app/src/main/jni/AutolinkingCompat.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
#define autolinking_cxxModuleProvider facebook::react::autolinking_cxxModuleProvider
1010
#define autolinking_registerProviders facebook::react::autolinking_registerProviders
1111

12-
#else // < 0.75
12+
#elif __has_include(<rncli.h>) // < 0.75
1313

1414
#include <rncli.h>
1515

1616
#define autolinking_ModuleProvider facebook::react::rncli_ModuleProvider
1717
#define autolinking_cxxModuleProvider facebook::react::rncli_cxxModuleProvider
1818
#define autolinking_registerProviders facebook::react::rncli_registerProviders
1919

20+
#else // Autolinking is handled elsewhere in the old architecture (paper)
21+
22+
#define REACTAPP_LEGACY_AUTOLINKING 1
23+
2024
#endif // __has_include(<autolinking.h>)
2125

2226
#endif // REACTAPP_JNI_AUTOLINKINGCOMPAT_H_

android/app/src/main/jni/ComponentsRegistry.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ void ComponentsRegistry::registerNatives()
3232

3333
facebook::react::DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint =
3434
[](std::shared_ptr<ComponentDescriptorProviderRegistry const> registry) {
35+
#ifndef REACTAPP_LEGACY_AUTOLINKING
3536
// Register providers generated by `@react-native-community/cli`
3637
autolinking_registerProviders(registry);
38+
#endif // !REACTAPP_LEGACY_AUTOLINKING
3739
};
3840
}
3941

android/app/src/main/jni/OnLoad.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using facebook::react::TurboModule;
1919

2020
namespace
2121
{
22+
#ifndef REACTAPP_LEGACY_AUTOLINKING
2223
std::shared_ptr<TurboModule> cxxModuleProvider(const std::string &name,
2324
const std::shared_ptr<CallInvoker> &jsInvoker)
2425
{
@@ -42,15 +43,18 @@ namespace
4243
// And we fallback to the module providers autolinked by RN CLI
4344
return autolinking_ModuleProvider(name, params);
4445
}
46+
#endif // !REACTAPP_LEGACY_AUTOLINKING
4547
} // namespace
4648

4749
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
4850
{
4951
return facebook::jni::initialize(vm, [] {
52+
#ifndef REACTAPP_LEGACY_AUTOLINKING
5053
DefaultTurboModuleManagerDelegate::cxxModuleProvider = &cxxModuleProvider;
5154
DefaultTurboModuleManagerDelegate::javaModuleProvider = &javaModuleProvider;
5255
DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint =
5356
&autolinking_registerProviders;
57+
#endif // !REACTAPP_LEGACY_AUTOLINKING
5458
});
5559
}
5660

android/app/src/main/jni/TurboModuleManagerDelegate.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ std::shared_ptr<TurboModule> TurboModuleManagerDelegate::getTurboModule(StringRe
2828
std::shared_ptr<TurboModule> TurboModuleManagerDelegate::getTurboModule(
2929
StringRef name, const JavaTurboModule::InitParams &params)
3030
{
31+
#ifndef REACTAPP_LEGACY_AUTOLINKING
3132
// Try autolinked module providers first
3233
auto module = autolinking_ModuleProvider(name, params);
3334
if (module != nullptr) {
3435
return module;
3536
}
37+
#endif // !REACTAPP_LEGACY_AUTOLINKING
3638

3739
return rncore_ModuleProvider(name, params);
3840
}

0 commit comments

Comments
 (0)