Skip to content

Commit 463f465

Browse files
authored
feat: Upgrade React Native binding to 1.13.1 (#13)
* chore: upgrade react native binding to 1.12 * chore: upgrade react native binding to 1.13.1 * chore: use published loro ffi 1.13.1
2 parents 509d436 + 23fc6f0 commit 463f465

13 files changed

Lines changed: 5537 additions & 4096 deletions

File tree

android/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ execute_process(
1111
OUTPUT_VARIABLE UNIFFI_BINDGEN_PATH
1212
OUTPUT_STRIP_TRAILING_WHITESPACE
1313
)
14-
string(REGEX
15-
REPLACE "/package\\.json$" ""
16-
UNIFFI_BINDGEN_PATH ${UNIFFI_BINDGEN_PATH}
17-
)
14+
# Get the directory; get_filename_component and cmake_path will normalize
15+
# paths with Windows path separators.
16+
get_filename_component(UNIFFI_BINDGEN_PATH "${UNIFFI_BINDGEN_PATH}" DIRECTORY)
1817

1918
# Specifies a path to native header files.
2019
include_directories(
@@ -38,6 +37,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all")
3837
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
3938
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
4039

40+
# Set linker flags for 16KB page size alignment (required for Android 15+)
41+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
42+
4143
cmake_path(
4244
SET MY_RUST_LIB
4345
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libloro_rs.a

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ android {
6767
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
6868
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
6969
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
70+
consumerProguardFiles 'proguard-rules.pro'
7071

7172
buildFeatures {
7273
prefab true

android/cpp-adapter.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,14 @@ Java_com_loro_lororeactnative_LoroReactNativeModule_nativeInstallRustCrate(
2424
jlong rtPtr,
2525
jobject callInvokerHolderJavaObj
2626
) {
27-
// https://github.com/realm/realm-js/blob/main/packages/realm/binding/android/src/main/cpp/io_realm_react_RealmReactModule.cpp#L122-L145
28-
// React Native uses the fbjni library for handling JNI, which has the concept of "hybrid objects",
29-
// which are Java objects containing a pointer to a C++ object. The CallInvokerHolder, which has the
30-
// invokeAsync method we want access to, is one such hybrid object.
31-
// Rather than reworking our code to use fbjni throughout, this code unpacks the C++ object from the Java
32-
// object `callInvokerHolderJavaObj` manually, based on reverse engineering the fbjni code.
33-
34-
// 1. Get the Java object referred to by the mHybridData field of the Java holder object
35-
auto callInvokerHolderClass = env->GetObjectClass(callInvokerHolderJavaObj);
36-
auto hybridDataField = env->GetFieldID(callInvokerHolderClass, "mHybridData", "Lcom/facebook/jni/HybridData;");
37-
auto hybridDataObj = env->GetObjectField(callInvokerHolderJavaObj, hybridDataField);
38-
39-
// 2. Get the destructor Java object referred to by the mDestructor field from the myHybridData Java object
40-
auto hybridDataClass = env->FindClass("com/facebook/jni/HybridData");
41-
auto destructorField =
42-
env->GetFieldID(hybridDataClass, "mDestructor", "Lcom/facebook/jni/HybridData$Destructor;");
43-
auto destructorObj = env->GetObjectField(hybridDataObj, destructorField);
44-
45-
// 3. Get the mNativePointer field from the mDestructor Java object
46-
auto destructorClass = env->FindClass("com/facebook/jni/HybridData$Destructor");
47-
auto nativePointerField = env->GetFieldID(destructorClass, "mNativePointer", "J");
48-
auto nativePointerValue = env->GetLongField(destructorObj, nativePointerField);
49-
50-
// 4. Cast the mNativePointer back to its C++ type
51-
auto nativePointer = reinterpret_cast<facebook::react::CallInvokerHolder*>(nativePointerValue);
52-
auto jsCallInvoker = nativePointer->getCallInvoker();
27+
using JCallInvokerHolder = facebook::react::CallInvokerHolder;
5328

29+
auto holderLocal = facebook::jni::make_local(callInvokerHolderJavaObj);
30+
auto holderRef = facebook::jni::static_ref_cast<JCallInvokerHolder::javaobject>(holderLocal);
31+
auto* holderCxx = holderRef->cthis();
32+
auto jsCallInvoker = holderCxx->getCallInvoker();
5433
auto runtime = reinterpret_cast<jsi::Runtime *>(rtPtr);
34+
5535
return lororeactnative::installRustCrate(*runtime, jsCallInvoker);
5636
}
5737

example/ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- hermes-engine (0.79.2):
99
- hermes-engine/Pre-built (= 0.79.2)
1010
- hermes-engine/Pre-built (0.79.2)
11-
- loro-react-native (1.10.3):
11+
- loro-react-native (1.13.1):
1212
- DoubleConversion
1313
- glog
1414
- hermes-engine
@@ -31,7 +31,7 @@ PODS:
3131
- ReactCodegen
3232
- ReactCommon/turbomodule/bridging
3333
- ReactCommon/turbomodule/core
34-
- uniffi-bindgen-react-native (= 0.28.3-5)
34+
- uniffi-bindgen-react-native (= 0.31.0-2)
3535
- Yoga
3636
- RCT-Folly (2024.11.18.00):
3737
- boost
@@ -1680,7 +1680,7 @@ PODS:
16801680
- React-perflogger (= 0.79.2)
16811681
- React-utils (= 0.79.2)
16821682
- SocketRocket (0.7.1)
1683-
- uniffi-bindgen-react-native (0.28.3-5):
1683+
- uniffi-bindgen-react-native (0.31.0-2):
16841684
- React-Core
16851685
- Yoga (0.0.0)
16861686

@@ -1917,7 +1917,7 @@ SPEC CHECKSUMS:
19171917
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
19181918
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
19191919
hermes-engine: 314be5250afa5692b57b4dd1705959e1973a8ebe
1920-
loro-react-native: ef58f3d1b3bf19efb88e422080ed52552bf5c693
1920+
loro-react-native: 20b44780910281515017a631b3f6003185366cef
19211921
RCT-Folly: 36fe2295e44b10d831836cc0d1daec5f8abcf809
19221922
RCTDeprecation: 83ffb90c23ee5cea353bd32008a7bca100908f8c
19231923
RCTRequired: eb7c0aba998009f47a540bec9e9d69a54f68136e
@@ -1981,7 +1981,7 @@ SPEC CHECKSUMS:
19811981
ReactCodegen: b9c6802762046e8000655cee5ba22f6422620f03
19821982
ReactCommon: 4d0da92a5eb8da86c08e3ec34bd23ab439fb2461
19831983
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
1984-
uniffi-bindgen-react-native: 018090e6c342b31e1189eb4d098860e9d44caa86
1984+
uniffi-bindgen-react-native: 205a15613d97a49fe17d5bda57f7fa46a7bbafd0
19851985
Yoga: c758bfb934100bb4bf9cbaccb52557cee35e8bdf
19861986

19871987
PODFILE CHECKSUM: a5ca260180a96f18394d1d29176689cad6469ad8

loro-react-native.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
1717

1818
s.source_files = "ios/**/*.{h,m,mm,swift}", "ios/generated/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}", "cpp/generated/**/*.{hpp,cpp,c,h}"
1919
s.vendored_frameworks = "build/LoroFfiFramework.xcframework"
20-
s.dependency "uniffi-bindgen-react-native", "0.28.3-5"
20+
s.dependency "uniffi-bindgen-react-native", "0.31.0-2"
2121

2222
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
2323
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
@@ -41,4 +41,4 @@ Pod::Spec.new do |s|
4141
s.dependency "ReactCommon/turbomodule/core"
4242
end
4343
end
44-
end
44+
end

0 commit comments

Comments
 (0)