From 4c1bdea81db6963bc8d932ec0e472e9b21796a8f Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 28 Nov 2023 13:17:22 -0800 Subject: [PATCH] CxxReactPackage: Load So's during class loads (#41674) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41674 The problem: The Java runtime couldn't find CatalystCxxReactPackage.initHybrid. Why: I think is because CxxReactPackage loads CatalystCxxReactPackage's so in its constructor. This might be too late to load the derived class's so. So, I just switched derived delegates to load the so in the static initializer (i.e: the recomended approch for so loading): https://www.internalfb.com/code/fbsource/[91c4e41c49ed191ac864250ccaec52c01ddaeccc]/fbandroid/libraries/soloader/java/com/facebook/soloader/SoLoader.java?lines=52-54%2C60-61%2C63-67 This way: 1. The So's are loaded plenty early (the method not found error went away). 2. We don't create our own so loading infra, which complicates this abstraction, and makes it harder to work with, even more. Changelog: [Internal] Reviewed By: javache Differential Revision: D51550622 fbshipit-source-id: f4782d6fa9387f21fbf611191e9483e2a58b3a34 --- .../facebook/react/runtime/cxxreactpackage/CxxReactPackage.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/cxxreactpackage/CxxReactPackage.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/cxxreactpackage/CxxReactPackage.kt index 34a77fa2154..bba110e7236 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/cxxreactpackage/CxxReactPackage.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/cxxreactpackage/CxxReactPackage.kt @@ -22,12 +22,9 @@ abstract class CxxReactPackage { protected abstract fun initHybrid(): HybridData protected constructor() { - maybeLoadOtherSoLibraries() mHybridData = initHybrid() } - @Synchronized protected open fun maybeLoadOtherSoLibraries(): Unit {} - companion object { init { SoLoader.loadLibrary("react_cxxreactpackage")