Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move libmapbufferjni.so inside libreactnative.so #46003

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ val preparePrefab by
listOf(
PrefabPreprocessingEntry(
"turbomodulejsijni", Pair("src/main/jni/react/turbomodule", "")),
PrefabPreprocessingEntry(
"react_newarchdefaults", Pair("src/main/jni/react/newarchdefaults", "")),
PrefabPreprocessingEntry(
"react_render_animations",
Pair("../ReactCommon/react/renderer/animations/", "react/renderer/animations/")),
Expand Down Expand Up @@ -120,8 +118,6 @@ val preparePrefab by
PrefabPreprocessingEntry("jsi", Pair("../ReactCommon/jsi/", "")),
PrefabPreprocessingEntry(
"fabricjni", Pair("src/main/jni/react/fabric", "react/fabric/")),
PrefabPreprocessingEntry(
"mapbufferjni", Pair("src/main/jni/react/mapbuffer", "react/mapbuffer/")),
PrefabPreprocessingEntry(
"react_render_mapbuffer",
Pair("../ReactCommon/react/renderer/mapbuffer/", "react/renderer/mapbuffer/")),
Expand Down Expand Up @@ -241,6 +237,8 @@ val preparePrefab by
listOf(
// glog
Pair(File(buildDir, "third-party-ndk/glog/exported/").absolutePath, ""),
// mapbufferjni
Pair("src/main/jni/react/mapbuffer", "react/mapbuffer/"),
// turbomodulejsijni
Pair("src/main/jni/react/turbomodule", ""),
// react_codegen_rncore
Expand Down Expand Up @@ -297,6 +295,8 @@ val preparePrefab by
Pair(
"../ReactCommon/react/renderer/components/textinput/platform/android/",
""),
// react_newarchdefaults
Pair("src/main/jni/react/newarchdefaults", ""),
// react_nativemodule_core
Pair(File(buildDir, "third-party-ndk/boost/boost_1_83_0/").absolutePath, ""),
Pair(File(buildDir, "third-party-ndk/double-conversion/").absolutePath, ""),
Expand Down Expand Up @@ -623,7 +623,6 @@ android {
"react_performance_timeline",
"react_utils",
"react_render_componentregistry",
"react_newarchdefaults",
"react_render_animations",
"react_render_consistency",
"react_render_dom",
Expand All @@ -633,7 +632,6 @@ android {
"rrc_root",
"jsi",
"fabricjni",
"mapbufferjni",
"react_render_mapbuffer",
"react_render_textlayoutmanager",
"yoga",
Expand Down Expand Up @@ -693,6 +691,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 @@ -723,9 +722,6 @@ android {
create("turbomodulejsijni") {
headers = File(prefabHeadersDir, "turbomodulejsijni").absolutePath
}
create("react_newarchdefaults") {
headers = File(prefabHeadersDir, "react_newarchdefaults").absolutePath
}
create("react_render_animations") {
headers = File(prefabHeadersDir, "react_render_animations").absolutePath
}
Expand All @@ -751,7 +747,6 @@ android {
create("rrc_root") { headers = File(prefabHeadersDir, "rrc_root").absolutePath }
create("jsi") { headers = File(prefabHeadersDir, "jsi").absolutePath }
create("fabricjni") { headers = File(prefabHeadersDir, "fabricjni").absolutePath }
create("mapbufferjni") { headers = File(prefabHeadersDir, "mapbufferjni").absolutePath }
create("react_render_mapbuffer") {
headers = File(prefabHeadersDir, "react_render_mapbuffer").absolutePath
}
Expand Down Expand Up @@ -791,19 +786,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 +819,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 @@ -66,10 +66,8 @@ target_compile_options(${CMAKE_PROJECT_NAME}
find_package(ReactAndroid REQUIRED CONFIG)
add_library(fabricjni ALIAS ReactAndroid::fabricjni)
add_library(jsi ALIAS ReactAndroid::jsi)
add_library(mapbufferjni ALIAS ReactAndroid::mapbufferjni)
add_library(react_render_mapbuffer ALIAS ReactAndroid::react_render_mapbuffer)
add_library(react_render_textlayoutmanager ALIAS ReactAndroid::react_render_textlayoutmanager)
add_library(react_newarchdefaults ALIAS ReactAndroid::react_newarchdefaults)
add_library(reactnative ALIAS ReactAndroid::reactnative)
add_library(turbomodulejsijni ALIAS ReactAndroid::turbomodulejsijni)
add_library(yoga ALIAS ReactAndroid::yoga)
Expand All @@ -79,10 +77,8 @@ add_library(fbjni ALIAS fbjni::fbjni)

target_link_libraries(${CMAKE_PROJECT_NAME}
fabricjni # prefab ready
mapbufferjni # prefab ready
fbjni # via 3rd party prefab
jsi # prefab ready
react_newarchdefaults # prefab ready
reactnative # prefab ready
turbomodulejsijni # prefab ready
yoga # prefab ready
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
17 changes: 15 additions & 2 deletions packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif(CCACHE_FOUND)

# Make sure every shared lib includes a .note.gnu.build-id header
add_link_options(-Wl,--build-id)
add_compile_options(-Wall -Werror -std=c++20)
add_compile_options(-Wall -Werror)

function(add_react_android_subdir relative_path)
add_subdirectory(${REACT_ANDROID_DIR}/${relative_path} ReactAndroid/${relative_path})
Expand Down Expand Up @@ -122,6 +122,7 @@ add_react_build_subdir(generated/source/codegen/jni)
add_react_android_subdir(src/main/jni/first-party/fb)
add_react_android_subdir(src/main/jni/first-party/fbgloginit)
add_react_android_subdir(src/main/jni/first-party/yogajni)
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)
Expand All @@ -140,14 +141,19 @@ add_react_android_subdir(src/main/jni/react/runtime/hermes/jni)
add_react_android_subdir(src/main/jni/react/runtime/jsc/jni)
add_react_android_subdir(src/main/jni/react/devsupport)

# SoMerging Utils
include(${REACT_ANDROID_DIR}/src/main/jni/first-party/jni-lib-merge/SoMerging-utils.cmake)

# libreactnative.so Dependency
#
# The React Native Android Library (the .aar) should expose headers only via this target.
# 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:jni_lib_merge_glue>
$<TARGET_OBJECTS:logger>
$<TARGET_OBJECTS:mapbufferjni>
$<TARGET_OBJECTS:react_bridging>
$<TARGET_OBJECTS:react_codegen_rncore>
$<TARGET_OBJECTS:react_debug>
Expand All @@ -158,6 +164,7 @@ add_library(reactnative
$<TARGET_OBJECTS:react_nativemodule_featureflags>
$<TARGET_OBJECTS:react_nativemodule_idlecallbacks>
$<TARGET_OBJECTS:react_nativemodule_microtasks>
$<TARGET_OBJECTS:react_newarchdefaults>
$<TARGET_OBJECTS:react_render_attributedstring>
$<TARGET_OBJECTS:react_render_componentregistry>
$<TARGET_OBJECTS:react_render_consistency>
Expand All @@ -183,19 +190,22 @@ add_library(reactnative
$<TARGET_OBJECTS:rrc_view>
$<TARGET_OBJECTS:runtimeexecutor>
)
target_merge_so(reactnative)

target_link_libraries(reactnative PUBLIC
double-conversion
fabricjni
fbjni
folly_runtime
glog
jsi
log
mapbufferjni
reactnativejni
yoga
)
target_include_directories(reactnative
PUBLIC
$<TARGET_PROPERTY:mapbufferjni,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_bridging,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_codegen_rncore,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_debug,INTERFACE_INCLUDE_DIRECTORIES>
Expand All @@ -206,6 +216,7 @@ target_include_directories(reactnative
$<TARGET_PROPERTY:react_nativemodule_idlecallbacks,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_nativemodule_featureflags,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_attributedstring,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_componentregistry,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_consistency,INTERFACE_INCLUDE_DIRECTORIES>
Expand Down Expand Up @@ -289,13 +300,15 @@ add_executable(reactnative_unittest
-DHERMES_ENABLE_DEBUGGER)

target_link_libraries(reactnative_unittest
fabricjni
folly_runtime
glog
glog_init
gtest_main
hermes-engine::libhermes
hermes_inspector_modern
jsi
mapbufferjni
react_cxxreact
react_codegen_rncore
react_debug
Expand Down
4 changes: 1 addition & 3 deletions packages/react-native/ReactAndroid/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
#include <fbjni/fbjni.h>

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(vm, [] {

});
return facebook::jni::initialize(vm, [] {});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

# This is the 'glue' library responsible of allowing to do so-merging in React Native
# OSS. This library contains just a .c file that is included in every merged library.
#
# The header file is included in every merged library during compilation and takes care
# of the redefinition of the JNI_OnLoad function to JNI_OnLoad_Weak.
#
# More on this mechanism: https://github.com/fbsamples/android-native-library-merging-demo

add_library(jni_lib_merge_glue OBJECT jni_lib_merge.c)

add_compile_options(-fexceptions -Wall)
add_definitions(-DJNI_MERGE_PRINT_ONLOAD)

target_include_directories(jni_lib_merge_glue PUBLIC jni-lib-merge)

target_link_libraries(jni_lib_merge_glue PUBLIC log)
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.

cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

# This function should be invoked if the requested library is going to be merged
# with libreactnative.so as such:
#
# target_merge_so(react_newarchdefaults)
#
# This function will take care of forcefully including the jni_lib_merge.h header that takes
# care of redefining the JNI_OnLoad function to JNI_OnLoad_Weak.
function(target_merge_so target_name)
target_compile_options(${target_name}
PRIVATE
-DORIGINAL_SONAME=\"lib${target_name}.so\"
-include ${REACT_ANDROID_DIR}/src/main/jni/first-party/jni-lib-merge/jni_lib_merge.h
)
target_link_options(${target_name} PRIVATE -Wl,--defsym=JNI_OnLoad=JNI_OnLoad_Weak)
endfunction()
Loading
Loading