fix: Fix Android build on React Native 0.65 and older (#694)
* fix: Fix Android build on React Native 0.65 and older * fix: Add excludes * fix: Ignore META-INF from package * fix: Wrong var name
This commit is contained in:
parent
dcbbae5fc7
commit
77e065d961
@ -10,6 +10,17 @@ set (RN_SO_DIR ${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/first-
|
|||||||
|
|
||||||
# VisionCamera shared
|
# VisionCamera shared
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
add_library(
|
add_library(
|
||||||
${PACKAGE_NAME}
|
${PACKAGE_NAME}
|
||||||
SHARED
|
SHARED
|
||||||
@ -31,11 +42,14 @@ file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")
|
|||||||
target_include_directories(
|
target_include_directories(
|
||||||
${PACKAGE_NAME}
|
${PACKAGE_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
# --- fbjni ---
|
||||||
"${LIBFBJNI_INCLUDE_DIR}"
|
"${LIBFBJNI_INCLUDE_DIR}"
|
||||||
|
# --- Third Party (required by RN) ---
|
||||||
"${BUILD_DIR}/third-party-ndk/boost"
|
"${BUILD_DIR}/third-party-ndk/boost"
|
||||||
"${BUILD_DIR}/third-party-ndk/double-conversion"
|
"${BUILD_DIR}/third-party-ndk/double-conversion"
|
||||||
"${BUILD_DIR}/third-party-ndk/folly"
|
"${BUILD_DIR}/third-party-ndk/folly"
|
||||||
"${BUILD_DIR}/third-party-ndk/glog"
|
"${BUILD_DIR}/third-party-ndk/glog"
|
||||||
|
# --- React Native ---
|
||||||
"${NODE_MODULES_DIR}/react-native/React"
|
"${NODE_MODULES_DIR}/react-native/React"
|
||||||
"${NODE_MODULES_DIR}/react-native/React/Base"
|
"${NODE_MODULES_DIR}/react-native/React/Base"
|
||||||
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
|
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
|
||||||
@ -44,6 +58,9 @@ target_include_directories(
|
|||||||
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
||||||
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
||||||
"${NODE_MODULES_DIR}/hermes-engine/android/include/"
|
"${NODE_MODULES_DIR}/hermes-engine/android/include/"
|
||||||
|
${INCLUDE_JSI_CPP} # only on older RN versions
|
||||||
|
${INCLUDE_JSIDYNAMIC_CPP} # only on older RN versions
|
||||||
|
# --- Reanimated ---
|
||||||
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Tools"
|
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Tools"
|
||||||
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SpecTools"
|
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SpecTools"
|
||||||
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SharedItems"
|
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SharedItems"
|
||||||
@ -87,12 +104,6 @@ find_library(
|
|||||||
PATHS ${LIBRN_DIR}
|
PATHS ${LIBRN_DIR}
|
||||||
NO_CMAKE_FIND_ROOT_PATH
|
NO_CMAKE_FIND_ROOT_PATH
|
||||||
)
|
)
|
||||||
find_library(
|
|
||||||
JSI_LIB
|
|
||||||
jsi
|
|
||||||
PATHS ${LIBRN_DIR}
|
|
||||||
NO_CMAKE_FIND_ROOT_PATH
|
|
||||||
)
|
|
||||||
find_library(
|
find_library(
|
||||||
FOLLY_JSON_LIB
|
FOLLY_JSON_LIB
|
||||||
folly_json
|
folly_json
|
||||||
@ -106,6 +117,18 @@ find_library(
|
|||||||
PATHS ${LIBRN_DIR}
|
PATHS ${LIBRN_DIR}
|
||||||
NO_CMAKE_FIND_ROOT_PATH
|
NO_CMAKE_FIND_ROOT_PATH
|
||||||
)
|
)
|
||||||
|
if(${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(
|
find_library(
|
||||||
REANIMATED_LIB
|
REANIMATED_LIB
|
||||||
|
@ -4,6 +4,10 @@ import java.nio.file.Paths
|
|||||||
|
|
||||||
def reactNative = new File("$projectDir/../node_modules/react-native")
|
def reactNative = new File("$projectDir/../node_modules/react-native")
|
||||||
|
|
||||||
|
def reactProperties = new Properties()
|
||||||
|
file("$projectDir/../node_modules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
||||||
|
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
|
||||||
|
|
||||||
def FOR_HERMES = System.getenv("FOR_HERMES") == "True"
|
def FOR_HERMES = System.getenv("FOR_HERMES") == "True"
|
||||||
rootProject.getSubprojects().forEach({project ->
|
rootProject.getSubprojects().forEach({project ->
|
||||||
if (project.plugins.hasPlugin("com.android.application")) {
|
if (project.plugins.hasPlugin("com.android.application")) {
|
||||||
@ -94,6 +98,7 @@ android {
|
|||||||
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
||||||
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
||||||
arguments '-DANDROID_STL=c++_shared',
|
arguments '-DANDROID_STL=c++_shared',
|
||||||
|
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
|
||||||
"-DNODE_MODULES_DIR=${rootDir}/../node_modules",
|
"-DNODE_MODULES_DIR=${rootDir}/../node_modules",
|
||||||
"-DFOR_HERMES=${FOR_HERMES}"
|
"-DFOR_HERMES=${FOR_HERMES}"
|
||||||
}
|
}
|
||||||
@ -111,7 +116,10 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so"]
|
// Exclude all Libraries that are already present in the user's app (through React Native or by him installing REA)
|
||||||
|
excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreactnativejni.so", "**/libfolly_json.so", "**/libreanimated.so", "**/libjscexecutor.so"]
|
||||||
|
// META-INF is duplicate by CameraX.
|
||||||
|
exclude "META-INF/**"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
Loading…
Reference in New Issue
Block a user