diff --git a/android/app/build.gradle b/android/app/build.gradle index 0ee8d79e6..96bd58126 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -125,7 +125,7 @@ android { resValue "string", "app_name", project.ext.react.appName def cppStd = reactNativeVersion >= v(0, 74, 0) ? "-std=c++20" : "-std=c++17" - if (enableNewArchitecture) { + if (reactNativeVersion >= v(0, 76, 0) || enableNewArchitecture) { externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared", diff --git a/android/app/src/main/jni/AutolinkingCompat.h b/android/app/src/main/jni/AutolinkingCompat.h index 6095fb30d..14cf36ba3 100644 --- a/android/app/src/main/jni/AutolinkingCompat.h +++ b/android/app/src/main/jni/AutolinkingCompat.h @@ -9,7 +9,7 @@ #define autolinking_cxxModuleProvider facebook::react::autolinking_cxxModuleProvider #define autolinking_registerProviders facebook::react::autolinking_registerProviders -#else // < 0.75 +#elif __has_include() // < 0.75 #include @@ -17,6 +17,10 @@ #define autolinking_cxxModuleProvider facebook::react::rncli_cxxModuleProvider #define autolinking_registerProviders facebook::react::rncli_registerProviders +#else // Autolinking is handled elsewhere in the old architecture (paper) + +#define REACTAPP_LEGACY_AUTOLINKING 1 + #endif // __has_include() #endif // REACTAPP_JNI_AUTOLINKINGCOMPAT_H_ diff --git a/android/app/src/main/jni/ComponentsRegistry.cpp b/android/app/src/main/jni/ComponentsRegistry.cpp index 83fa11687..7c02b37d5 100644 --- a/android/app/src/main/jni/ComponentsRegistry.cpp +++ b/android/app/src/main/jni/ComponentsRegistry.cpp @@ -32,8 +32,10 @@ void ComponentsRegistry::registerNatives() facebook::react::DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint = [](std::shared_ptr registry) { +#ifndef REACTAPP_LEGACY_AUTOLINKING // Register providers generated by `@react-native-community/cli` autolinking_registerProviders(registry); +#endif // !REACTAPP_LEGACY_AUTOLINKING }; } diff --git a/android/app/src/main/jni/OnLoad.cpp b/android/app/src/main/jni/OnLoad.cpp index 526f82eb6..2e1ffb883 100644 --- a/android/app/src/main/jni/OnLoad.cpp +++ b/android/app/src/main/jni/OnLoad.cpp @@ -19,6 +19,7 @@ using facebook::react::TurboModule; namespace { +#ifndef REACTAPP_LEGACY_AUTOLINKING std::shared_ptr cxxModuleProvider(const std::string &name, const std::shared_ptr &jsInvoker) { @@ -42,15 +43,18 @@ namespace // And we fallback to the module providers autolinked by RN CLI return autolinking_ModuleProvider(name, params); } +#endif // !REACTAPP_LEGACY_AUTOLINKING } // namespace JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { return facebook::jni::initialize(vm, [] { +#ifndef REACTAPP_LEGACY_AUTOLINKING DefaultTurboModuleManagerDelegate::cxxModuleProvider = &cxxModuleProvider; DefaultTurboModuleManagerDelegate::javaModuleProvider = &javaModuleProvider; DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint = &autolinking_registerProviders; +#endif // !REACTAPP_LEGACY_AUTOLINKING }); } diff --git a/android/app/src/main/jni/TurboModuleManagerDelegate.cpp b/android/app/src/main/jni/TurboModuleManagerDelegate.cpp index 0ce690ef5..8983cfd72 100644 --- a/android/app/src/main/jni/TurboModuleManagerDelegate.cpp +++ b/android/app/src/main/jni/TurboModuleManagerDelegate.cpp @@ -28,11 +28,13 @@ std::shared_ptr TurboModuleManagerDelegate::getTurboModule(StringRe std::shared_ptr TurboModuleManagerDelegate::getTurboModule( StringRef name, const JavaTurboModule::InitParams ¶ms) { +#ifndef REACTAPP_LEGACY_AUTOLINKING // Try autolinked module providers first auto module = autolinking_ModuleProvider(name, params); if (module != nullptr) { return module; } +#endif // !REACTAPP_LEGACY_AUTOLINKING return rncore_ModuleProvider(name, params); }