Skip to content

Commit

Permalink
Do not depend on OSS SoLoader anymore (facebook#45873)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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
  • Loading branch information
cortinico authored and facebook-github-bot committed Aug 12, 2024
1 parent 7e41ea4 commit 6376ea3
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 9 deletions.
13 changes: 8 additions & 5 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ android {
"src/main/res/views/alert",
"src/main/res/views/modal",
"src/main/res/views/uimanager"))
kotlin.srcDir(project.file("../sdks/ossonly-soloader/src/main/java"))
java.exclude("com/facebook/react/processing")
java.exclude("com/facebook/react/module/processing")
}
Expand Down Expand Up @@ -791,19 +792,19 @@ android {
tasks.withType<KotlinCompile>().configureEach { exclude("com/facebook/annotationprocessors/**") }

dependencies {
implementation(libs.fresco)
implementation(libs.fresco.middleware)
implementation(libs.fresco.imagepipeline.okhttp3)
implementation(libs.fresco.ui.common)

api(libs.androidx.appcompat)
api(libs.androidx.appcompat.resources)
api(libs.androidx.autofill)
api(libs.androidx.swiperefreshlayout)
api(libs.androidx.tracing)

api(libs.fbjni)
api(libs.fresco)
api(libs.fresco.middleware)
api(libs.fresco.imagepipeline.okhttp3)
api(libs.fresco.ui.common)
api(libs.infer.annotation)
api(libs.soloader)
api(libs.yoga.proguard.annotations)

api(libs.jsr305)
Expand All @@ -824,6 +825,8 @@ dependencies {
testImplementation(libs.thoughtworks)
}

configurations.all { exclude(group = "com.facebook.soloader") }

react {
// TODO: The library name is chosen for parity with Fabric components & iOS
// This should be changed to a more generic name, e.g. `ReactCoreSpec`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ android {

dependencies {
implementation(libs.fbjni)
implementation(libs.soloader)
implementation(libs.yoga.proguard.annotations)
implementation(libs.androidx.annotation)
}
Expand All @@ -316,6 +315,8 @@ android {
}
}

configurations.all { exclude(group = "com.facebook.soloader") }

afterEvaluate {
if (!overrideHermesDir) {
// If you're not specifying a Hermes Path override, we want to
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ nexus-publish = "1.3.0"
okhttp = "4.9.2"
okio = "2.9.0"
robolectric = "4.9.2"
soloader = "0.11.0"
xstream = "1.4.20"
yoga-proguard-annotations = "1.19.0"
# Native Dependencies
Expand All @@ -56,7 +55,6 @@ fresco-middleware = { module = "com.facebook.fresco:middleware", version.ref = "
fresco-imagepipeline-okhttp3 = { module = "com.facebook.fresco:imagepipeline-okhttp3", version.ref = "fresco" }
fresco-ui-common = { module = "com.facebook.fresco:ui-common", version.ref = "fresco" }
infer-annotation = { module = "com.facebook.infer.annotation:infer-annotation", version.ref = "infer-annotation" }
soloader = { module = "com.facebook.soloader:soloader", version.ref = "soloader" }
yoga-proguard-annotations = { module = "com.facebook.yoga:proguard-annotations", version.ref = "yoga-proguard-annotations" }

jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" }
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"scripts/react-native-xcode.sh",
"sdks/.hermesversion",
"sdks/hermes-engine",
"sdks/ossonly-soloader",
"sdks/hermesc",
"settings.gradle.kts",
"src",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.soloader

public annotation class DoNotOptimize {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.
*/

@file:Suppress("UNUSED_EXPRESSION", "ControlFlowWithEmptyBody", "UNUSED_PARAMETER")

package com.facebook.soloader

import android.content.Context

/**
* This class is a stub of SoLoader used ONLY by React Native OSS.
*
* This allows us to do not mutate the SoLoader.init and SoLoader.loadLibrary methods, which are
* used by the React Native, while also allowing us to implement custom JNI_OnLoad calling which
* enables merging of SOs.
*/
public object SoLoader {

private val loadedLibraries = mutableSetOf<String>()

private fun mapLibName(input: String) = input

@Suppress("UNUSED_PARAMETER")
private fun invokeJniOnload(libraryName: String) {
// no-op for now, till we move library to So Merging in OSS
}

@Deprecated("This method is a no-op and you should not be calling it")
@JvmStatic
public fun init(context: Context, exoPackage: Boolean) {
// Do nothing
}

@JvmStatic
public fun loadLibrary(libraryName: String): Boolean {
if (libraryName in loadedLibraries) {
return false
}
val mapLibraryName = mapLibName(libraryName)
System.loadLibrary(mapLibraryName)
if (libraryName != mapLibraryName) {
invokeJniOnload(mapLibraryName)
}
return true
}

@JvmStatic
public fun setInTestMode() {
// Do nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.soloader.nativeloader

/**
* This class is a stub of NativeLoader used ONLY by React Native OSS.
*
* Fresco in OSS depends on NativeLoader, but we don't want to include the real
* NativeLoader/SoLoader in React Native OSS. This stub is used to make Fresco work properly for us.
*/
public object NativeLoader {

@JvmStatic
public fun loadLibrary(libraryName: String): Boolean {
System.loadLibrary(libraryName)
return true
}

@JvmStatic public fun isInitialized(): Boolean = true

@Suppress("UNUSED_PARAMETER")
public fun initIfUninitialized(systemDelegate: SystemDelegate): Unit = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.soloader.nativeloader

/**
* This class is a stub of NativeLoaderDelegate used ONLY by React Native OSS.
*
* Fresco in OSS depends on NativeLoader, but we don't want to include the real
* NativeLoader/SoLoader in React Native OSS. This stub is used to make Fresco work properly for us.
*/
public interface NativeLoaderDelegate {

public fun loadLibrary(shortName: String?, flags: Int): Boolean

public fun getLibraryPath(libName: String?): String

public fun getSoSourcesVersion(): Int
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.soloader.nativeloader

public class SystemDelegate {}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ class RNTesterApplication : Application(), ReactApplication {
override fun onCreate() {
ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik)
super.onCreate()
SoLoader.init(this, /* native exopackage */ false)

// We want the .init() statement to exercise this code when building RNTester with Buck
@Suppress("DEPRECATION") SoLoader.init(this, /* native exopackage */ false)

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
load()
Expand Down

0 comments on commit 6376ea3

Please sign in to comment.