Skip to content

Commit 7bd35a3

Browse files
fix(android): work with RN 76
Signed-off-by: Berend Sliedrecht <[email protected]>
1 parent 395e390 commit 7bd35a3

File tree

6 files changed

+1281
-3048
lines changed

6 files changed

+1281
-3048
lines changed

examples/askar-react-native-example/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"version": "1.0.0",
66
"orientation": "portrait",
77
"icon": "./assets/icon.png",
8+
"newArchEnabled": true,
89
"userInterfaceStyle": "light",
910
"splash": {
1011
"image": "./assets/splash.png",

examples/askar-react-native-example/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
},
1212
"dependencies": {
1313
"@openwallet-foundation/askar-react-native": "workspace:*",
14-
"expo": "~51.0.2",
15-
"expo-status-bar": "~1.12.1",
16-
"react": "18.2.0",
17-
"react-native": "0.74.1"
14+
"expo": "~52.0.27",
15+
"expo-status-bar": "~2.0.1",
16+
"react": "18.3.1",
17+
"react-native": "~0.76.6"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.20.0",
2121
"@babel/runtime": "^7.22.15",
22-
"@types/react": "~18.2.45",
23-
"typescript": "~5.4.5"
22+
"@types/react": "~18.3.18",
23+
"typescript": "~5.3.3"
2424
}
2525
}

packages/askar-react-native/android/CMakeLists.txt

Lines changed: 16 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@ project(askarreactnative)
22
cmake_minimum_required(VERSION 3.4.1)
33

44
set (PACKAGE_NAME "askarreactnative")
5-
set (LIB_NAME "askar")
65
file (GLOB LIBASKAR_DIR "${CMAKE_SOURCE_DIR}/../native/mobile/android/${ANDROID_ABI}")
76

87
set(CMAKE_VERBOSE_MAKEFILE ON)
98
set(CMAKE_CXX_STANDARD 20)
10-
119
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
12-
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
13-
find_package(fbjni REQUIRED CONFIG)
14-
find_package(ReactAndroid REQUIRED CONFIG)
15-
else()
16-
set (RN_SO_DIR ${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/first-party/react/jni)
17-
endif()
1810

19-
if(${REACT_NATIVE_VERSION} LESS 66)
20-
set (INCLUDE_JSI_CPP "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp")
21-
set (INCLUDE_JSIDYNAMIC_CPP "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/JSIDynamic.cpp")
22-
endif()
11+
find_package(fbjni REQUIRED CONFIG)
12+
find_package(ReactAndroid REQUIRED CONFIG)
2313

2414
include_directories(
2515
../cpp
@@ -36,90 +26,14 @@ add_library(
3626
../cpp/askar.cpp
3727
)
3828

39-
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
40-
target_include_directories(
41-
${PACKAGE_NAME}
42-
PRIVATE
43-
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
44-
"${NODE_MODULES_DIR}/react-native/ReactCommon"
45-
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
46-
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
47-
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/renderer/graphics/platform/cxx"
48-
"${NODE_MODULES_DIR}/react-native/ReactCommon/runtimeexecutor"
49-
"${NODE_MODULES_DIR}/react-native/ReactCommon/yoga"
50-
)
51-
else()
52-
file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")
53-
54-
target_include_directories(
55-
${PACKAGE_NAME}
56-
PRIVATE
57-
"${LIBFBJNI_INCLUDE_DIR}"
58-
"${NODE_MODULES_DIR}/react-native/React"
59-
"${NODE_MODULES_DIR}/react-native/React/Base"
60-
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
61-
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
62-
"${NODE_MODULES_DIR}/react-native/ReactCommon"
63-
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
64-
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
65-
${INCLUDE_JSI_CPP} # only on older RN versions
66-
${INCLUDE_JSIDYNAMIC_CPP} # only on older RN versions
67-
)
68-
endif()
69-
70-
file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
71-
72-
if(${REACT_NATIVE_VERSION} LESS 71)
73-
find_library(
74-
FBJNI_LIB
75-
fbjni
76-
PATHS ${LIBRN_DIR}
77-
NO_CMAKE_FIND_ROOT_PATH
78-
)
79-
endif()
80-
81-
if(${REACT_NATIVE_VERSION} LESS 71)
82-
find_library(
83-
REACT_NATIVE_JNI_LIB
84-
reactnativejni
85-
PATHS ${LIBRN_DIR}
86-
NO_CMAKE_FIND_ROOT_PATH
87-
)
88-
endif()
89-
90-
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
91-
target_link_libraries(
92-
${PACKAGE_NAME}
93-
ReactAndroid::jsi
94-
ReactAndroid::reactnativejni
95-
fbjni::fbjni
96-
)
97-
elseif(${REACT_NATIVE_VERSION} LESS 66)
98-
# JSI lib didn't exist on RN 0.65 and before. Simply omit it.
99-
set (JSI_LIB "")
100-
else()
101-
# RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
102-
find_library(
103-
JSI_LIB
104-
jsi
105-
PATHS ${LIBRN_DIR}
106-
NO_CMAKE_FIND_ROOT_PATH
107-
)
108-
endif()
109-
110-
find_library(
111-
REANIMATED_LIB
112-
reanimated
113-
PATHS ${LIBREANIMATED_DIR}
114-
NO_CMAKE_FIND_ROOT_PATH
115-
)
116-
117-
find_library(
118-
LOG_LIB
119-
log
29+
target_include_directories(
30+
${PACKAGE_NAME}
31+
PRIVATE
32+
"${NODE_MODULES_DIR}/react-native/ReactCommon"
33+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
34+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
12035
)
12136

122-
12337
find_library(
12438
ASKAR_LIB
12539
# TODO(rename): when lib has changed
@@ -132,12 +46,15 @@ if (NOT ASKAR_LIB)
13246
message(FATAL_ERROR "Could not find ASKAR_LIB at: ${LIBASKAR_DIR}")
13347
endif()
13448

49+
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
50+
target_link_libraries(${PACKAGE_NAME} ReactAndroid::reactnative)
51+
else()
52+
target_link_libraries(${PACKAGE_NAME} ReactAndroid::reactnativejni)
53+
endif()
54+
13555
target_link_libraries(
13656
${PACKAGE_NAME}
13757
${ASKAR_LIB}
138-
${LOG_LIB}
139-
${JSI_LIB}
140-
${REACT_NATIVE_JNI_LIB}
141-
${FBJNI_LIB}
142-
android
58+
ReactAndroid::jsi
59+
fbjni::fbjni
14360
)

packages/askar-react-native/android/build.gradle

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def reactNative = new File("$nodeModules/react-native")
4949
def CMAKE_NODE_MODULES_DIR = project.getProjectDir().getParentFile().getParent()
5050
def reactProperties = new Properties()
5151
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
52-
def REACT_NATIVE_FULL_VERSION = reactProperties.getProperty("VERSION_NAME")
5352
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
5453

5554
apply plugin: 'com.android.library'
@@ -78,10 +77,8 @@ android {
7877
buildToolsVersion getExt('buildToolsVersion')
7978
ndkVersion getExt('ndkVersion')
8079

81-
if (REACT_NATIVE_VERSION >= 71) {
82-
buildFeatures {
83-
prefab true
84-
}
80+
buildFeatures {
81+
prefab true
8582
}
8683

8784
defaultConfig {
@@ -107,12 +104,11 @@ android {
107104
}
108105

109106
packagingOptions {
110-
excludes = ["**/libc++_shared.so",
111-
"**/libfbjni.so",
112-
"**/libjsi.so",
113-
"**/libreactnativejni.so",
114-
"**/libjscexecutor.so",
115-
]
107+
if (REACT_NATIVE_VERSION >= 76) {
108+
excludes = ["**/libjsi.so", "**/libreactnative.so" ]
109+
} else {
110+
excludes = ["**/libjsi.so", "**/libreactnativejni.so" ]
111+
}
116112
}
117113

118114
buildTypes {
@@ -214,28 +210,7 @@ repositories {
214210

215211

216212
dependencies {
217-
if (REACT_NATIVE_VERSION >= 71) {
218-
implementation "com.facebook.react:react-android:"
219-
} else {
220-
// noinspection GradleDynamicVersion
221-
implementation 'com.facebook.react:react-native:' + REACT_NATIVE_FULL_VERSION
222-
}
223-
224-
if (REACT_NATIVE_VERSION < 71) {
225-
//noinspection GradleDynamicVersion
226-
extractHeaders("com.facebook.fbjni:fbjni:+:headers")
227-
//noinspection GradleDynamicVersion
228-
extractJNI("com.facebook.fbjni:fbjni:+")
229-
230-
def rnAarMatcher = "**/react-native/**/*${resolveBuildType()}.aar"
231-
if (REACT_NATIVE_VERSION < 69) {
232-
rnAarMatcher = "**/**/*.aar"
233-
}
234-
235-
def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
236-
def jscAAR = fileTree("${nodeModules}/jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
237-
extractJNI(files(rnAAR, jscAAR))
238-
}
213+
implementation "com.facebook.react:react-android:"
239214
}
240215

241216
def downloadsDir = new File("$buildDir/downloads")

packages/askar-react-native/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
},
4242
"devDependencies": {
4343
"react": "18.2.0",
44-
"react-native": "0.74.1",
44+
"react-native": ">= 0.71",
4545
"typescript": "~5.4.5"
4646
},
4747
"peerDependencies": {
4848
"react": ">= 16",
49-
"react-native": ">= 0.66.0"
49+
"react-native": ">= 0.71"
5050
},
5151
"binary": {
5252
"module_name": "askar",

0 commit comments

Comments
 (0)