Skip to content

Commit 6dc01da

Browse files
cortinicofacebook-github-bot
authored andcommitted
Do not depend on OSS SoLoader anymore (#45873)
Summary: Pull Request resolved: #45873 I'm removing the Gradle dependency on OSS SoLoader and stubbing it with our own implementation. This will allow us to implement merging of further .so libraries and As Fresco also depends on SoLoader, I had to stub the `NativeLoader` dependency as well. Changelog: [Android] [Breaking] - Do not depend on OSS SoLoader anymore and do not expose Fresco `api` dependency. Reviewed By: mdvacca Differential Revision: D60652007 fbshipit-source-id: 6e70a5c37ba9337fbe8772e192b886ba4693c7f1
1 parent 53969cb commit 6dc01da

File tree

10 files changed

+140
-9
lines changed

10 files changed

+140
-9
lines changed

packages/react-native/ReactAndroid/build.gradle.kts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ android {
693693
"src/main/res/views/alert",
694694
"src/main/res/views/modal",
695695
"src/main/res/views/uimanager"))
696+
kotlin.srcDir(project.file("../sdks/ossonly-soloader/src/main/java"))
696697
java.exclude("com/facebook/react/processing")
697698
java.exclude("com/facebook/react/module/processing")
698699
}
@@ -791,19 +792,19 @@ android {
791792
tasks.withType<KotlinCompile>().configureEach { exclude("com/facebook/annotationprocessors/**") }
792793

793794
dependencies {
795+
implementation(libs.fresco)
796+
implementation(libs.fresco.middleware)
797+
implementation(libs.fresco.imagepipeline.okhttp3)
798+
implementation(libs.fresco.ui.common)
799+
794800
api(libs.androidx.appcompat)
795801
api(libs.androidx.appcompat.resources)
796802
api(libs.androidx.autofill)
797803
api(libs.androidx.swiperefreshlayout)
798804
api(libs.androidx.tracing)
799805

800806
api(libs.fbjni)
801-
api(libs.fresco)
802-
api(libs.fresco.middleware)
803-
api(libs.fresco.imagepipeline.okhttp3)
804-
api(libs.fresco.ui.common)
805807
api(libs.infer.annotation)
806-
api(libs.soloader)
807808
api(libs.yoga.proguard.annotations)
808809

809810
api(libs.jsr305)
@@ -824,6 +825,8 @@ dependencies {
824825
testImplementation(libs.thoughtworks)
825826
}
826827

828+
configurations.all { exclude(group = "com.facebook.soloader") }
829+
827830
react {
828831
// TODO: The library name is chosen for parity with Fabric components & iOS
829832
// This should be changed to a more generic name, e.g. `ReactCoreSpec`.

packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ android {
290290

291291
dependencies {
292292
implementation(libs.fbjni)
293-
implementation(libs.soloader)
294293
implementation(libs.yoga.proguard.annotations)
295294
implementation(libs.androidx.annotation)
296295
}
@@ -316,6 +315,8 @@ android {
316315
}
317316
}
318317

318+
configurations.all { exclude(group = "com.facebook.soloader") }
319+
319320
afterEvaluate {
320321
if (!overrideHermesDir) {
321322
// If you're not specifying a Hermes Path override, we want to

packages/react-native/gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ nexus-publish = "1.3.0"
2929
okhttp = "4.9.2"
3030
okio = "2.9.0"
3131
robolectric = "4.9.2"
32-
soloader = "0.11.0"
3332
xstream = "1.4.20"
3433
yoga-proguard-annotations = "1.19.0"
3534
# Native Dependencies
@@ -56,7 +55,6 @@ fresco-middleware = { module = "com.facebook.fresco:middleware", version.ref = "
5655
fresco-imagepipeline-okhttp3 = { module = "com.facebook.fresco:imagepipeline-okhttp3", version.ref = "fresco" }
5756
fresco-ui-common = { module = "com.facebook.fresco:ui-common", version.ref = "fresco" }
5857
infer-annotation = { module = "com.facebook.infer.annotation:infer-annotation", version.ref = "infer-annotation" }
59-
soloader = { module = "com.facebook.soloader:soloader", version.ref = "soloader" }
6058
yoga-proguard-annotations = { module = "com.facebook.yoga:proguard-annotations", version.ref = "yoga-proguard-annotations" }
6159

6260
jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" }

packages/react-native/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"scripts/react-native-xcode.sh",
8383
"sdks/.hermesversion",
8484
"sdks/hermes-engine",
85+
"sdks/ossonly-soloader",
8586
"sdks/hermesc",
8687
"settings.gradle.kts",
8788
"src",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.soloader
9+
10+
public annotation class DoNotOptimize {}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
@file:Suppress("UNUSED_EXPRESSION", "ControlFlowWithEmptyBody", "UNUSED_PARAMETER")
9+
10+
package com.facebook.soloader
11+
12+
import android.content.Context
13+
14+
/**
15+
* This class is a stub of SoLoader used ONLY by React Native OSS.
16+
*
17+
* This allows us to do not mutate the SoLoader.init and SoLoader.loadLibrary methods, which are
18+
* used by the React Native, while also allowing us to implement custom JNI_OnLoad calling which
19+
* enables merging of SOs.
20+
*/
21+
public object SoLoader {
22+
23+
private val loadedLibraries = mutableSetOf<String>()
24+
25+
private fun mapLibName(input: String) = input
26+
27+
@Suppress("UNUSED_PARAMETER")
28+
private fun invokeJniOnload(libraryName: String) {
29+
// no-op for now, till we move library to So Merging in OSS
30+
}
31+
32+
@Deprecated("This method is a no-op and you should not be calling it")
33+
@JvmStatic
34+
public fun init(context: Context, exoPackage: Boolean) {
35+
// Do nothing
36+
}
37+
38+
@JvmStatic
39+
public fun loadLibrary(libraryName: String): Boolean {
40+
if (libraryName in loadedLibraries) {
41+
return false
42+
}
43+
val mapLibraryName = mapLibName(libraryName)
44+
System.loadLibrary(mapLibraryName)
45+
if (libraryName != mapLibraryName) {
46+
invokeJniOnload(mapLibraryName)
47+
}
48+
return true
49+
}
50+
51+
@JvmStatic
52+
public fun setInTestMode() {
53+
// Do nothing
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.soloader.nativeloader
9+
10+
/**
11+
* This class is a stub of NativeLoader used ONLY by React Native OSS.
12+
*
13+
* Fresco in OSS depends on NativeLoader, but we don't want to include the real
14+
* NativeLoader/SoLoader in React Native OSS. This stub is used to make Fresco work properly for us.
15+
*/
16+
public object NativeLoader {
17+
18+
@JvmStatic
19+
public fun loadLibrary(libraryName: String): Boolean {
20+
System.loadLibrary(libraryName)
21+
return true
22+
}
23+
24+
@JvmStatic public fun isInitialized(): Boolean = true
25+
26+
@Suppress("UNUSED_PARAMETER")
27+
public fun initIfUninitialized(systemDelegate: SystemDelegate): Unit = Unit
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.soloader.nativeloader
9+
10+
/**
11+
* This class is a stub of NativeLoaderDelegate used ONLY by React Native OSS.
12+
*
13+
* Fresco in OSS depends on NativeLoader, but we don't want to include the real
14+
* NativeLoader/SoLoader in React Native OSS. This stub is used to make Fresco work properly for us.
15+
*/
16+
public interface NativeLoaderDelegate {
17+
18+
public fun loadLibrary(shortName: String?, flags: Int): Boolean
19+
20+
public fun getLibraryPath(libName: String?): String
21+
22+
public fun getSoSourcesVersion(): Int
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.soloader.nativeloader
9+
10+
public class SystemDelegate {}

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ class RNTesterApplication : Application(), ReactApplication {
128128
override fun onCreate() {
129129
ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik)
130130
super.onCreate()
131-
SoLoader.init(this, /* native exopackage */ false)
131+
132+
// We want the .init() statement to exercise this code when building RNTester with Buck
133+
@Suppress("DEPRECATION") SoLoader.init(this, /* native exopackage */ false)
132134

133135
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
134136
load()

0 commit comments

Comments
 (0)