Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android build #112

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ updates:
interval: "weekly"
labels:
- "dependencies"
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "monthly"
labels:
- "dependencies"
# - package-ecosystem: "npm"
# directory: "./"
# schedule:
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "tensorflow"]
path = tensorflow
url = https://github.com/tensorflow/tensorflow
19 changes: 15 additions & 4 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ find_package(fbjni REQUIRED CONFIG)
find_library(
TFLITE
tensorflowlite_jni
PATHS "./src/main/cpp/lib/tensorflow/jni/${ANDROID_ABI}"
PATHS "./src/main/cpp/lib/litert/jni/${ANDROID_ABI}"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)

find_library(
TFLITE_GPU
tensorflowlite_gpu_jni
PATHS "./src/main/cpp/lib/tensorflow/jni/${ANDROID_ABI}"
PATHS "./src/main/cpp/lib/litert/jni/${ANDROID_ABI}"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
Expand All @@ -42,7 +42,7 @@ target_include_directories(
PRIVATE
"../cpp"
"src/main/cpp"
"../tensorflow/"
"src/main/cpp/lib/litert/headers"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it really extract here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the headers used in TensorflowPlugin.h are extracted to this location.

image

"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule" # <-- CallInvokerHolder JNI wrapper
Expand All @@ -54,8 +54,19 @@ target_link_libraries(
${PACKAGE_NAME}
android # <-- log
ReactAndroid::jsi # <-- jsi.h
ReactAndroid::reactnativejni # <-- CallInvokerImpl
fbjni::fbjni # <-- fbjni.h
${TFLITE}
${TFLITE_GPU}
)

if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::reactnative # <-- RN merged so
)
else()
target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::reactnativejni # <-- CallInvokerImpl
)
endif()
28 changes: 24 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ android {
"**/libc++_shared.so",
"**/libfbjni.so",
"**/libjsi.so",
"**/libreactnative.so",
"**/libreactnativejni.so",
"**/libturbomodulejsijni.so",
"**/libreact_nativemodule_core.so",
"**/libtensorflowlite_jni.so",
"**/libtensorflowlite_gpu_jni.so",
]
}
buildTypes {
Expand Down Expand Up @@ -123,12 +126,28 @@ dependencies {
implementation "com.facebook.react:react-native:+"

// Tensorflow Lite .aar (includes C API via prefabs)
implementation "org.tensorflow:tensorflow-lite:2.16.1"
extractSO("org.tensorflow:tensorflow-lite:2.16.1")
implementation "com.google.ai.edge.litert:litert:1.0.1"
extractSO("com.google.ai.edge.litert:litert:1.0.1")
extractHeaders("com.google.ai.edge.litert:litert:1.0.1")

// Tensorflow Lite GPU delegate
implementation "org.tensorflow:tensorflow-lite-gpu:2.16.1"
extractSO("org.tensorflow:tensorflow-lite-gpu:2.16.1")
implementation "com.google.ai.edge.litert:litert-gpu:1.0.1"
extractSO("com.google.ai.edge.litert:litert-gpu:1.0.1")
extractHeaders("com.google.ai.edge.litert:litert-gpu:1.0.1")
}

task extractAARHeaders {
doLast {
configurations.extractHeaders.files.each {
def file = it.absoluteFile
def packageName = file.name.tokenize('-')[0]
copy {
from zipTree(file)
into "src/main/cpp/lib/$packageName/"
include "**/*.h"
}
}
}
}

task extractSOFiles {
Expand Down Expand Up @@ -166,5 +185,6 @@ def nativeBuildDependsOn(dependsOnTask) {
}

afterEvaluate {
nativeBuildDependsOn(extractAARHeaders)
nativeBuildDependsOn(extractSOFiles)
}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"src",
"lib",
"android/src",
"!android/src/main/cpp/lib",
"android/build.gradle",
"android/CMakeLists.txt",
"android/gradle.properties",
Expand All @@ -26,14 +27,11 @@
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
"lint-cpp": "scripts/clang-format.sh",
"prepare": "git submodule update --init --recursive",
"update-submodule": "git submodule update --remote --merge",
"check-all": "scripts/check-all.sh",
"prepack": "bob build",
"release": "release-it",
"example": "yarn --cwd example",
"configure": "git submodule update --init --recursive && cd tensorflow && ./configure",
"bootstrap": "yarn && yarn example && yarn example pods && yarn configure"
"bootstrap": "yarn && yarn example && yarn example pods"
},
"keywords": [
"react-native",
Expand Down
1 change: 0 additions & 1 deletion tensorflow
Submodule tensorflow deleted from e960f1
Loading