Skip to content

Commit

Permalink
fix(android): always include ReactNative-application.cmake on 0.76 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Nov 8, 2024
1 parent 2cf1350 commit c1a56a7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion android/app/src/main/jni/AutolinkingCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
#define autolinking_cxxModuleProvider facebook::react::autolinking_cxxModuleProvider
#define autolinking_registerProviders facebook::react::autolinking_registerProviders

#else // < 0.75
#elif __has_include(<rncli.h>) // < 0.75

#include <rncli.h>

#define autolinking_ModuleProvider facebook::react::rncli_ModuleProvider
#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(<autolinking.h>)

#endif // REACTAPP_JNI_AUTOLINKINGCOMPAT_H_
2 changes: 2 additions & 0 deletions android/app/src/main/jni/ComponentsRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ void ComponentsRegistry::registerNatives()

facebook::react::DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint =
[](std::shared_ptr<ComponentDescriptorProviderRegistry const> registry) {
#ifndef REACTAPP_LEGACY_AUTOLINKING
// Register providers generated by `@react-native-community/cli`
autolinking_registerProviders(registry);
#endif // !REACTAPP_LEGACY_AUTOLINKING
};
}

Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using facebook::react::TurboModule;

namespace
{
#ifndef REACTAPP_LEGACY_AUTOLINKING
std::shared_ptr<TurboModule> cxxModuleProvider(const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker)
{
Expand All @@ -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
});
}

Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/jni/TurboModuleManagerDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ std::shared_ptr<TurboModule> TurboModuleManagerDelegate::getTurboModule(StringRe
std::shared_ptr<TurboModule> TurboModuleManagerDelegate::getTurboModule(
StringRef name, const JavaTurboModule::InitParams &params)
{
#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);
}
Expand Down

0 comments on commit c1a56a7

Please sign in to comment.