diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt index 131804140ee901..2cf0b6908e4936 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt @@ -27,6 +27,10 @@ private constructor(componentFactory: ComponentFactory) { @DoNotStrip private external fun initHybrid(componentFactory: ComponentFactory): HybridData + init { + DefaultSoLoader.maybeLoadSoLibrary() + } + companion object { @JvmStatic @DoNotStrip diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt index fa6ff875dda211..ca6cf331a103d4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt @@ -8,7 +8,6 @@ package com.facebook.react.defaults import com.facebook.react.config.ReactFeatureFlags -import com.facebook.soloader.SoLoader /** * A utility class that serves as an entry point for users setup the New Architecture. @@ -27,8 +26,7 @@ object DefaultNewArchitectureEntryPoint { fun load( turboModulesEnabled: Boolean = true, fabricEnabled: Boolean = true, - bridgelessEnabled: Boolean = false, - dynamicLibraryName: String = "appmodules", + bridgelessEnabled: Boolean = false ) { ReactFeatureFlags.useTurboModules = turboModulesEnabled ReactFeatureFlags.enableFabricRenderer = fabricEnabled @@ -42,8 +40,7 @@ object DefaultNewArchitectureEntryPoint { this.privateConcurrentReactEnabled = fabricEnabled this.privateBridgelessEnabled = bridgelessEnabled - SoLoader.loadLibrary("react_newarchdefaults") - SoLoader.loadLibrary(dynamicLibraryName) + DefaultSoLoader.maybeLoadSoLibrary() } @Deprecated( @@ -56,9 +53,8 @@ object DefaultNewArchitectureEntryPoint { fabricEnabled: Boolean = true, bridgelessEnabled: Boolean = false, @Suppress("UNUSED_PARAMETER") concurrentReactEnabled: Boolean = true, - dynamicLibraryName: String = "appmodules", ) { - load(turboModulesEnabled, fabricEnabled, bridgelessEnabled, dynamicLibraryName) + load(turboModulesEnabled, fabricEnabled, bridgelessEnabled) } private var privateFabricEnabled: Boolean = false diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultSoLoader.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultSoLoader.kt new file mode 100644 index 00000000000000..99c9ebdf4f0b44 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultSoLoader.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.defaults + +import com.facebook.soloader.SoLoader +import com.facebook.soloader.SoLoaderDSONotFoundError + +internal class DefaultSoLoader { + companion object { + @Synchronized + @JvmStatic + fun maybeLoadSoLibrary() { + SoLoader.loadLibrary("react_newarchdefaults") + try { + SoLoader.loadLibrary("appmodules") + } catch (e: SoLoaderDSONotFoundError) { + // ignore: DefaultTurboModuleManagerDelegate is still used in apps that don't have + // appmodules.so + } + } + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt index ac1fd1a4c7d90c..9ea51d49f4f2a3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt @@ -30,4 +30,8 @@ private constructor(context: ReactApplicationContext, packages: List) = DefaultTurboModuleManagerDelegate(context, packages) } + + override fun maybeLoadOtherSoLibraries() { + DefaultSoLoader.maybeLoadSoLibrary() + } }