From 5b2bbb84b14208905fc0dd7eade9ee6ce6e079b7 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 21 Nov 2024 05:55:58 -0800 Subject: [PATCH] Include autolinkin.h in OnLoad.cpp only if it exists (#47875) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47875 The old architecture looks broken because in the OnLoad.cpp file we try to include the autolinking.h header which is only generated when the New Architecture is enabled. This fix guards the include and the usage of the function provided by the autolinking so that the old architecture should work as well. ## Changelog [Internal] - Include autolinkin.h in OnLoad.cpp only if it exists Reviewed By: blakef Differential Revision: D66295318 fbshipit-source-id: 18461e6b70ac92af57b805bef51c0df49db02283 --- .../cmake-utils/default-app-setup/OnLoad.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp b/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp index db2e6c199e4..1e2420d0e5b 100644 --- a/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp +++ b/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp @@ -29,7 +29,12 @@ #include #include +#if __has_include("") +#define AUTOLINKING_AVAILABLE 1 #include +#else +#define AUTOLINKING_AVAILABLE 0 +#endif #include #include #include @@ -56,8 +61,10 @@ void registerComponents( REACT_NATIVE_APP_COMPONENT_REGISTRATION(registry); #endif +#if AUTOLINKING_AVAILABLE // And we fallback to the components autolinked autolinking_registerProviders(registry); +#endif } std::shared_ptr cxxModuleProvider( @@ -71,8 +78,12 @@ std::shared_ptr cxxModuleProvider( // return std::make_shared(jsInvoker); // } +#if AUTOLINKING_AVAILABLE // And we fallback to the CXX module providers autolinked return autolinking_cxxModuleProvider(name, jsInvoker); +#endif + + return nullptr; } std::shared_ptr javaModuleProvider( @@ -101,10 +112,12 @@ std::shared_ptr javaModuleProvider( return module; } +#if AUTOLINKING_AVAILABLE // And we fallback to the module providers autolinked if (auto module = autolinking_ModuleProvider(name, params)) { return module; } +#endif return nullptr; }