Skip to content

Commit

Permalink
fix(android): work with RN 76
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored and Berend Sliedrecht committed Jan 27, 2025
1 parent cdba964 commit 45ee96f
Show file tree
Hide file tree
Showing 6 changed files with 1,281 additions and 3,048 deletions.
1 change: 1 addition & 0 deletions examples/askar-react-native-example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"newArchEnabled": true,
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
Expand Down
12 changes: 6 additions & 6 deletions examples/askar-react-native-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
},
"dependencies": {
"@openwallet-foundation/askar-react-native": "workspace:*",
"expo": "~51.0.2",
"expo-status-bar": "~1.12.1",
"react": "18.2.0",
"react-native": "0.74.1"
"expo": "~52.0.27",
"expo-status-bar": "~2.0.1",
"react": "18.3.1",
"react-native": "~0.76.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/runtime": "^7.22.15",
"@types/react": "~18.2.45",
"typescript": "~5.4.5"
"@types/react": "~18.3.18",
"typescript": "~5.3.3"
}
}
115 changes: 16 additions & 99 deletions packages/askar-react-native/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ project(askarreactnative)
cmake_minimum_required(VERSION 3.4.1)

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

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 20)

set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
else()
set (RN_SO_DIR ${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/first-party/react/jni)
endif()

if(${REACT_NATIVE_VERSION} LESS 66)
set (INCLUDE_JSI_CPP "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp")
set (INCLUDE_JSIDYNAMIC_CPP "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/JSIDynamic.cpp")
endif()
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)

include_directories(
../cpp
Expand All @@ -36,90 +26,14 @@ add_library(
../cpp/askar.cpp
)

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/renderer/graphics/platform/cxx"
"${NODE_MODULES_DIR}/react-native/ReactCommon/runtimeexecutor"
"${NODE_MODULES_DIR}/react-native/ReactCommon/yoga"
)
else()
file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")

target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${LIBFBJNI_INCLUDE_DIR}"
"${NODE_MODULES_DIR}/react-native/React"
"${NODE_MODULES_DIR}/react-native/React/Base"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
${INCLUDE_JSI_CPP} # only on older RN versions
${INCLUDE_JSIDYNAMIC_CPP} # only on older RN versions
)
endif()

file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")

if(${REACT_NATIVE_VERSION} LESS 71)
find_library(
FBJNI_LIB
fbjni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

if(${REACT_NATIVE_VERSION} LESS 71)
find_library(
REACT_NATIVE_JNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::jsi
ReactAndroid::reactnativejni
fbjni::fbjni
)
elseif(${REACT_NATIVE_VERSION} LESS 66)
# JSI lib didn't exist on RN 0.65 and before. Simply omit it.
set (JSI_LIB "")
else()
# RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
find_library(
JSI_LIB
jsi
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

find_library(
REANIMATED_LIB
reanimated
PATHS ${LIBREANIMATED_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

find_library(
LOG_LIB
log
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
)


find_library(
ASKAR_LIB
# TODO(rename): when lib has changed
Expand All @@ -132,12 +46,15 @@ if (NOT ASKAR_LIB)
message(FATAL_ERROR "Could not find ASKAR_LIB at: ${LIBASKAR_DIR}")
endif()

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
target_link_libraries(${PACKAGE_NAME} ReactAndroid::reactnative)
else()
target_link_libraries(${PACKAGE_NAME} ReactAndroid::reactnativejni)
endif()

target_link_libraries(
${PACKAGE_NAME}
${ASKAR_LIB}
${LOG_LIB}
${JSI_LIB}
${REACT_NATIVE_JNI_LIB}
${FBJNI_LIB}
android
ReactAndroid::jsi
fbjni::fbjni
)
41 changes: 8 additions & 33 deletions packages/askar-react-native/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def reactNative = new File("$nodeModules/react-native")
def CMAKE_NODE_MODULES_DIR = project.getProjectDir().getParentFile().getParent()
def reactProperties = new Properties()
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
def REACT_NATIVE_FULL_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()

apply plugin: 'com.android.library'
Expand Down Expand Up @@ -78,10 +77,8 @@ android {
buildToolsVersion getExt('buildToolsVersion')
ndkVersion getExt('ndkVersion')

if (REACT_NATIVE_VERSION >= 71) {
buildFeatures {
prefab true
}
buildFeatures {
prefab true
}

defaultConfig {
Expand All @@ -107,12 +104,11 @@ android {
}

packagingOptions {
excludes = ["**/libc++_shared.so",
"**/libfbjni.so",
"**/libjsi.so",
"**/libreactnativejni.so",
"**/libjscexecutor.so",
]
if (REACT_NATIVE_VERSION >= 76) {
excludes = ["**/libjsi.so", "**/libreactnative.so" ]
} else {
excludes = ["**/libjsi.so", "**/libreactnativejni.so" ]
}
}

buildTypes {
Expand Down Expand Up @@ -214,28 +210,7 @@ repositories {


dependencies {
if (REACT_NATIVE_VERSION >= 71) {
implementation "com.facebook.react:react-android:"
} else {
// noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:' + REACT_NATIVE_FULL_VERSION
}

if (REACT_NATIVE_VERSION < 71) {
//noinspection GradleDynamicVersion
extractHeaders("com.facebook.fbjni:fbjni:+:headers")
//noinspection GradleDynamicVersion
extractJNI("com.facebook.fbjni:fbjni:+")

def rnAarMatcher = "**/react-native/**/*${resolveBuildType()}.aar"
if (REACT_NATIVE_VERSION < 69) {
rnAarMatcher = "**/**/*.aar"
}

def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
def jscAAR = fileTree("${nodeModules}/jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
extractJNI(files(rnAAR, jscAAR))
}
implementation "com.facebook.react:react-android:"
}

def downloadsDir = new File("$buildDir/downloads")
Expand Down
4 changes: 2 additions & 2 deletions packages/askar-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
},
"devDependencies": {
"react": "18.2.0",
"react-native": "0.74.1",
"react-native": ">= 0.71",
"typescript": "~5.4.5"
},
"peerDependencies": {
"react": ">= 16",
"react-native": ">= 0.66.0"
"react-native": ">= 0.71"
},
"binary": {
"module_name": "askar",
Expand Down
Loading

0 comments on commit 45ee96f

Please sign in to comment.