Skip to content

Commit

Permalink
Merge all the remaining .so libraries into libreactnative.so (#46059)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46059

This merges all the remaining dynamic libraries into libreactnative.so.
Sadly I couldn't split this in smaller diffs as all the libraries are connected with each other.

I also had to introduce 2 other SOs: `libhermestooling.so` and `libjsctooling.so` which contains
all the necessary libs used when loading either JSC or Hermes. They need to be isolated
as RNGP will remove those libraries based on the library the user decides to pick.

Changelog:
[Android] [Breaking] - Merge all the remaining .so libraries into libreactnative.so

Reviewed By: hezi

Differential Revision: D61376496

fbshipit-source-id: ab9e725b7acbebdfd8fa3ff36ad34d080044bf0e
  • Loading branch information
cortinico authored and facebook-github-bot committed Aug 16, 2024
1 parent 7916f7e commit db80d78
Show file tree
Hide file tree
Showing 31 changed files with 261 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,9 @@ internal object NdkConfiguratorUtils {
"**/libfbjni.so",
// Those are prefab libraries we distribute via ReactAndroid
// Due to a bug in AGP, they fire a warning on console as both the JNI
// and the prefab .so files gets considered. See more on:
"**/libfabricjni.so",
"**/libfolly_runtime.so",
"**/libglog.so",
// and the prefab .so files gets considered.
"**/libreactnative.so",
"**/libjsi.so",
"**/libmapbufferjni.so",
"**/libreact_codegen_rncore.so",
"**/libreact_debug.so",
"**/libreact_nativemodule_core.so",
"**/libreact_newarchdefaults.so",
"**/libreact_cxxreactpackage.so",
"**/libreact_render_componentregistry.so",
"**/libreact_render_core.so",
"**/libreact_render_debug.so",
"**/libreact_render_graphics.so",
"**/libreact_render_imagemanager.so",
"**/libreact_render_mapbuffer.so",
"**/libreact_utils.so",
"**/librrc_image.so",
"**/librrc_legacyviewmanagerinterop.so",
"**/librrc_view.so",
"**/libruntimeexecutor.so",
"**/libturbomodulejsijni.so",
"**/libyoga.so",
// AGP will give priority of libc++_shared coming from App modules.
"**/libc++_shared.so",
))
Expand Down Expand Up @@ -144,14 +123,14 @@ internal object NdkConfiguratorUtils {
val includes = mutableListOf<String>()
if (hermesEnabled) {
excludes.add("**/libjsc.so")
excludes.add("**/libjscexecutor.so")
excludes.add("**/libjsctooling.so")
includes.add("**/libhermes.so")
includes.add("**/libhermes_executor.so")
includes.add("**/libhermestooling.so")
} else {
excludes.add("**/libhermes.so")
excludes.add("**/libhermes_executor.so")
excludes.add("**/libhermestooling.so")
includes.add("**/libjsc.so")
includes.add("**/libjscexecutor.so")
includes.add("**/libjsctooling.so")
}
return excludes to includes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.facebook.react.tests.*
import com.facebook.react.tests.createProject
import com.facebook.react.tests.createTestTask
import java.io.File
import org.assertj.Assert.assertThat
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ class NdkConfiguratorUtilsTest {
fun getPackagingOptionsForVariant_withHermesEnabled() {
val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = true)

assertThat(excludes).containsExactly("**/libjsc.so", "**/libjscexecutor.so")
assertThat(includes).doesNotContain("**/libjsc.so", "**/libjscexecutor.so")
assertThat(excludes).containsExactly("**/libjsc.so", "**/libjsctooling.so")
assertThat(includes).doesNotContain("**/libjsc.so", "**/libjsctooling.so")

assertThat(includes).containsExactly("**/libhermes.so", "**/libhermes_executor.so")
assertThat(excludes).doesNotContain("**/libhermes.so", "**/libhermes_executor.so")
assertThat(includes).containsExactly("**/libhermes.so", "**/libhermestooling.so")
assertThat(excludes).doesNotContain("**/libhermes.so", "**/libhermestooling.so")
}

@Test
fun getPackagingOptionsForVariant_withHermesDisabled() {
val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = false)

assertThat(excludes).containsExactly("**/libhermes.so", "**/libhermes_executor.so")
assertThat(includes).doesNotContain("**/libhermes.so", "**/libhermes_executor.so")
assertThat(excludes).containsExactly("**/libhermes.so", "**/libhermestooling.so")
assertThat(includes).doesNotContain("**/libhermes.so", "**/libhermestooling.so")

assertThat(includes).containsExactly("**/libjsc.so", "**/libjscexecutor.so")
assertThat(excludes).doesNotContain("**/libjsc.so", "**/libjscexecutor.so")
assertThat(includes).containsExactly("**/libjsc.so", "**/libjsctooling.so")
assertThat(excludes).doesNotContain("**/libjsc.so", "**/libjsctooling.so")
}
}
115 changes: 14 additions & 101 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,100 +81,29 @@ val preparePrefab by
input.set(
listOf(
PrefabPreprocessingEntry("jsi", Pair("../ReactCommon/jsi/", "")),
PrefabPreprocessingEntry(
"folly_runtime",
listOf(
Pair(File(buildDir, "third-party-ndk/fmt/include/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/folly/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/boost/boost_1_83_0/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/double-conversion/").absolutePath, ""),
)),
PrefabPreprocessingEntry(
"react_nativemodule_core",
listOf(
Pair(File(buildDir, "third-party-ndk/boost/boost_1_83_0/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/double-conversion/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/fmt/include/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/folly/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/glog/exported/").absolutePath, ""),
Pair("../ReactCommon/callinvoker/", ""),
Pair("../ReactCommon/cxxreact/", "cxxreact/"),
Pair("../ReactCommon/react/bridging/", "react/bridging/"),
Pair("../ReactCommon/react/config/", "react/config/"),
Pair("../ReactCommon/react/nativemodule/core/", ""),
Pair("../ReactCommon/react/nativemodule/core/platform/android/", ""),
Pair(
"../ReactCommon/react/renderer/componentregistry/",
"react/renderer/componentregistry/"),
Pair(
"../ReactCommon/react/renderer/components/root/",
"react/renderer/components/root/"),
Pair("../ReactCommon/react/renderer/core/", "react/renderer/core/"),
Pair("../ReactCommon/react/renderer/debug/", "react/renderer/debug/"),
Pair(
"../ReactCommon/react/renderer/leakchecker/",
"react/renderer/leakchecker/"),
Pair("../ReactCommon/react/renderer/mapbuffer/", "react/renderer/mapbuffer/"),
Pair("../ReactCommon/react/renderer/mounting/", "react/renderer/mounting/"),
Pair(
"../ReactCommon/react/renderer/runtimescheduler/",
"react/renderer/runtimescheduler/"),
Pair("../ReactCommon/react/renderer/scheduler/", "react/renderer/scheduler/"),
Pair("../ReactCommon/react/renderer/telemetry/", "react/renderer/telemetry/"),
Pair("../ReactCommon/react/renderer/uimanager/", "react/renderer/uimanager/"),
Pair("../ReactCommon/react/debug/", "react/debug/"),
Pair("../ReactCommon/react/utils/", "react/utils/"),
Pair("src/main/jni/react/jni", "react/jni/"),
// From: react_cxxreactpackage
Pair("src/main/jni/react/runtime/cxxreactpackage", ""),
)),
PrefabPreprocessingEntry(
"react_utils",
Pair("../ReactCommon/react/utils/", "react/utils/"),
),
PrefabPreprocessingEntry(
"react_render_imagemanager",
listOf(
Pair(
"../ReactCommon/react/renderer/imagemanager/",
"react/renderer/imagemanager/"),
Pair("../ReactCommon/react/renderer/imagemanager/platform/cxx/", ""),
)),
// These prefab targets are used by Expo & Reanimated
PrefabPreprocessingEntry(
"hermes_executor",
// "hermes_executor" is statically linking against "hermes_executor_common"
// and "hermes_inspector_modern". Here we expose only the headers that we know are
// needed.
Pair("../ReactCommon/hermes/inspector-modern/", "hermes/inspector-modern/")),
PrefabPreprocessingEntry(
"jscexecutor",
// "jscexecutor" is statically linking against "jscruntime"
// Here we expose only the headers that we know are needed.
Pair("../ReactCommon/jsc/", "jsc/")),
PrefabPreprocessingEntry(
"reactnativejni",
listOf(
Pair("src/main/jni/react/jni", "react/jni/"),
Pair("../ReactCommon/cxxreact/", "cxxreact/"),
)),
PrefabPreprocessingEntry(
"jsinspector",
Pair("../ReactCommon/jsinspector-modern/", "jsinspector-modern/"),
),
PrefabPreprocessingEntry(
"reactnative",
listOf(
// hermes_executor
// This prefab targets is used by Expo & Reanimated
Pair("../ReactCommon/hermes/inspector-modern/", "hermes/inspector-modern/"),
// jscexecutor
Pair("../ReactCommon/jsc/", "jsc/"),
// fabricjni
Pair("src/main/jni/react/fabric", "react/fabric/"),
// glog
Pair(File(buildDir, "third-party-ndk/glog/exported/").absolutePath, ""),
// jsiinpsector
Pair("../ReactCommon/jsinspector-modern/", "jsinspector-modern/"),
// mapbufferjni
Pair("src/main/jni/react/mapbuffer", "react/mapbuffer/"),
// turbomodulejsijni
Pair("src/main/jni/react/turbomodule", ""),
// react_codegen_rncore
Pair(File(buildDir, "generated/source/codegen/jni/").absolutePath, ""),
// reactnativejni
Pair("src/main/jni/react/jni", "react/jni/"),
Pair("../ReactCommon/cxxreact/", "cxxreact/"),
// react_featureflags
Pair("../ReactCommon/react/featureflags/", "react/featureflags/"),
// react_render_animations
Expand Down Expand Up @@ -567,23 +496,11 @@ android {
"-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON")

targets(
"jsijniprofiler",
"reactnativeblob",
"bridgeless",
"rninstance",
"hermesinstancejni",
"jscinstance",
"react_devsupportjni",
// prefab targets
"reactnativejni",
"react_utils",
"react_render_componentregistry",
"react_render_dom",
"reactnative",
"jsi",
"hermes_executor",
"jscexecutor",
"jsinspector",
"reactnative")
"hermestooling",
"jsctooling",
)
}
}
ndk { abiFilters.addAll(reactNativeArchitectures()) }
Expand Down Expand Up @@ -662,10 +579,6 @@ android {

prefab {
create("jsi") { headers = File(prefabHeadersDir, "jsi").absolutePath }
create("reactnativejni") { headers = File(prefabHeadersDir, "reactnativejni").absolutePath }
create("hermes_executor") { headers = File(prefabHeadersDir, "hermes_executor").absolutePath }
create("jscexecutor") { headers = File(prefabHeadersDir, "jscexecutor").absolutePath }
create("jsinspector") { headers = File(prefabHeadersDir, "jsinspector").absolutePath }
create("reactnative") { headers = File(prefabHeadersDir, "reactnative").absolutePath }
}

Expand Down
53 changes: 36 additions & 17 deletions packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ add_react_android_subdir(src/main/jni/first-party/jni-lib-merge)
add_react_android_subdir(src/main/jni/react/jni)
add_react_android_subdir(src/main/jni/react/reactperflogger)
add_react_android_subdir(src/main/jni/react/jscexecutor)
add_react_android_subdir(src/main/jni/react/jsctooling)
add_react_android_subdir(src/main/jni/react/turbomodule)
add_react_android_subdir(src/main/jni/react/uimanager)
add_react_android_subdir(src/main/jni/react/mapbuffer)
Expand All @@ -134,6 +135,7 @@ add_react_android_subdir(src/main/jni/react/fabric)
add_react_android_subdir(src/main/jni/react/featureflags)
add_react_android_subdir(src/main/jni/react/newarchdefaults)
add_react_android_subdir(src/main/jni/react/hermes/reactexecutor)
add_react_android_subdir(src/main/jni/react/hermes/tooling)
add_react_android_subdir(src/main/jni/react/hermes/instrumentation/)
add_react_android_subdir(src/main/jni/react/runtime/cxxreactpackage)
add_react_android_subdir(src/main/jni/react/runtime/jni)
Expand All @@ -150,21 +152,23 @@ include(${REACT_ANDROID_DIR}/src/main/jni/first-party/jni-lib-merge/SoMerging-ut
# This is needed in order to reduce the number of .so files that we ship in the final library
add_library(reactnative
SHARED
OnLoad.cpp
$<TARGET_OBJECTS:bridgeless>
$<TARGET_OBJECTS:bridgelessnativeviewconfig>
$<TARGET_OBJECTS:bridgelesshermes>
$<TARGET_OBJECTS:callinvokerholder>
$<TARGET_OBJECTS:fabricjni>
$<TARGET_OBJECTS:hermes_inspector_modern>
$<TARGET_OBJECTS:hermesinstancejni>
$<TARGET_OBJECTS:glog_init>
$<TARGET_OBJECTS:jni_lib_merge_glue>
$<TARGET_OBJECTS:jserrorhandler>
$<TARGET_OBJECTS:jsinspector>
$<TARGET_OBJECTS:jsireact>
$<TARGET_OBJECTS:logger>
$<TARGET_OBJECTS:mapbufferjni>
$<TARGET_OBJECTS:react_bridging>
$<TARGET_OBJECTS:react_codegen_rncore>
$<TARGET_OBJECTS:react_config>
$<TARGET_OBJECTS:react_cxxreact>
$<TARGET_OBJECTS:react_debug>
$<TARGET_OBJECTS:react_devsupportjni>
$<TARGET_OBJECTS:react_featureflags>
$<TARGET_OBJECTS:react_featureflagsjni>
$<TARGET_OBJECTS:react_nativemodule_core>
Expand All @@ -174,6 +178,7 @@ add_library(reactnative
$<TARGET_OBJECTS:react_nativemodule_idlecallbacks>
$<TARGET_OBJECTS:react_nativemodule_microtasks>
$<TARGET_OBJECTS:react_newarchdefaults>
$<TARGET_OBJECTS:react_performance_timeline>
$<TARGET_OBJECTS:react_render_animations>
$<TARGET_OBJECTS:react_render_attributedstring>
$<TARGET_OBJECTS:react_render_componentregistry>
Expand All @@ -188,12 +193,16 @@ add_library(reactnative
$<TARGET_OBJECTS:react_render_mapbuffer>
$<TARGET_OBJECTS:react_render_mounting>
$<TARGET_OBJECTS:react_render_observers_events>
$<TARGET_OBJECTS:react_render_runtimescheduler>
$<TARGET_OBJECTS:react_render_scheduler>
$<TARGET_OBJECTS:react_render_telemetry>
$<TARGET_OBJECTS:react_render_textlayoutmanager>
$<TARGET_OBJECTS:react_render_uimanager>
$<TARGET_OBJECTS:react_render_uimanager_consistency>
$<TARGET_OBJECTS:react_utils>
$<TARGET_OBJECTS:reactnativeblob>
$<TARGET_OBJECTS:reactnativejni>
$<TARGET_OBJECTS:reactperflogger>
$<TARGET_OBJECTS:rninstance>
$<TARGET_OBJECTS:rrc_image>
$<TARGET_OBJECTS:rrc_legacyviewmanagerinterop>
Expand All @@ -213,31 +222,36 @@ add_library(reactnative
)
target_merge_so(reactnative)

target_link_libraries(reactnative PUBLIC
double-conversion
fbjni
folly_runtime
glog
jsi
log
reactnativejni
yoga
hermes-engine::libhermes
target_link_libraries(reactnative
PUBLIC
android
double-conversion
fb
fbjni
folly_runtime
glog
jsi
log
yogacore
)

target_include_directories(reactnative
PUBLIC
$<TARGET_PROPERTY:bridgeless,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:bridgelessnativeviewconfig,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:bridgelesshermes,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:callinvokerholder,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:fabricjni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:hermes_inspector_modern,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:hermesinstancejni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:glog_init,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:jserrorhandler,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:jsinspector,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:jsireact,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:mapbufferjni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_bridging,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_codegen_rncore,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_config,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_cxxreact,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_debug,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_devsupportjni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_featureflags,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_featureflagsjni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_nativemodule_core,INTERFACE_INCLUDE_DIRECTORIES>
Expand All @@ -247,6 +261,7 @@ target_include_directories(reactnative
$<TARGET_PROPERTY:react_nativemodule_idlecallbacks,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_performance_timeline,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_animations,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_attributedstring,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_componentregistry,INTERFACE_INCLUDE_DIRECTORIES>
Expand All @@ -262,12 +277,16 @@ target_include_directories(reactnative
$<TARGET_PROPERTY:react_render_mapbuffer,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_mounting,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_observers_events,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_runtimescheduler,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_scheduler,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_telemetry,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_textlayoutmanager,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_uimanager,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_uimanager_consistency,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_utils,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:reactnativeblob,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:reactnativejni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:reactperflogger,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:rninstance,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:rrc_image,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:rrc_legacyviewmanagerinterop,INTERFACE_INCLUDE_DIRECTORIES>
Expand Down
Loading

0 comments on commit db80d78

Please sign in to comment.