Skip to content

Commit

Permalink
fix android cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Oct 16, 2024
1 parent a5c65d8 commit ce4522e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
40 changes: 26 additions & 14 deletions package/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ find_library(LOG_LIB log)
add_definitions(-DEGL_EGLEXT_PROTOTYPES)
add_definitions(-DGL_GLEXT_PROTOTYPES)

if (ENABLE_FRAME_PROCESSORS)
if(ENABLE_FRAME_PROCESSORS)
add_definitions(-DVISION_CAMERA_ENABLE_FRAME_PROCESSORS=true)
else()
add_definitions(-DVISION_CAMERA_ENABLE_FRAME_PROCESSORS=false)
endif()


# Add react-native-vision-camera sources
add_library(
${PACKAGE_NAME}
SHARED

# Java JNI
src/main/cpp/VisionCamera.cpp
src/main/cpp/MutableJByteBuffer.cpp

# Frame Processor
src/main/cpp/frameprocessors/FrameHostObject.cpp
src/main/cpp/frameprocessors/FrameProcessorPluginHostObject.cpp
Expand Down Expand Up @@ -57,20 +58,31 @@ target_include_directories(
# Link everything together
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB} # <-- Logcat logger
android # <-- Android JNI core
ReactAndroid::jsi # <-- RN: JSI
ReactAndroid::reactnativejni # <-- RN: React Native JNI bindings
fbjni::fbjni # <-- fbjni
${LOG_LIB} # <-- Logcat logger
android # <-- Android JNI core
ReactAndroid::jsi # <-- RN: JSI
ReactAndroid::reactnativejni # <-- RN: React Native JNI bindings
fbjni::fbjni # <-- fbjni
)

# Optionally also add Frame Processors here
message("VisionCamera: Frame Processors: ${ENABLE_FRAME_PROCESSORS}!")
if (ENABLE_FRAME_PROCESSORS)
message("VisionCamera: Linking react-native-worklets...")
find_package(react-native-worklets-core REQUIRED CONFIG)
target_link_libraries(
${PACKAGE_NAME}
react-native-worklets-core::rnworklets
)

if(ENABLE_FRAME_PROCESSORS)
message("VisionCamera: Linking react-native-worklets...")

message("VisionCamera: IS_NEW_ARCHITECTURE_ENABLED: ${IS_NEW_ARCHITECTURE_ENABLED}!")

if(IS_NEW_ARCHITECTURE_ENABLED)
target_link_libraries(
${PACKAGE_NAME}
react-native-worklets-core
)
else()
find_package(react-native-worklets-core REQUIRED CONFIG)
target_link_libraries(
${PACKAGE_NAME}
react-native-worklets-core::rnworklets
)
endif()
endif()
8 changes: 6 additions & 2 deletions package/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ if (hasWorklets) {
def enableCodeScanner = safeExtGetBool('VisionCamera_enableCodeScanner', false)
logger.warn("[VisionCamera] VisionCamera_enableCodeScanner is set to $enableCodeScanner!")

def isNewArchEnabled = isNewArchitectureEnabled()
logger.warn("[VisionCamera] New Architecture is ${isNewArchEnabled ? "enabled" : "disabled"}!")

repositories {
google()
mavenCentral()
Expand Down Expand Up @@ -126,14 +129,15 @@ android {
targetSdkVersion safeExtGet("targetSdkVersion", 34)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchEnabled.toString()

externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
arguments "-DANDROID_STL=c++_shared",
"-DNODE_MODULES_DIR=${nodeModules}",
"-DENABLE_FRAME_PROCESSORS=${enableFrameProcessors ? "ON" : "OFF"}"
"-DENABLE_FRAME_PROCESSORS=${enableFrameProcessors ? "ON" : "OFF"}",
"-DIS_NEW_ARCHITECTURE_ENABLED=${isNewArchEnabled ? "ON" : "OFF"}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down

0 comments on commit ce4522e

Please sign in to comment.