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
This commit is contained in:
Ramanpreet Nara
2023-11-28 13:17:22 -08:00
committed by Facebook GitHub Bot
parent 00e70354ca
commit 4c1bdea81d
@@ -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")