Skip to content

Commit ccbe815

Browse files
authored
fix: Fix android build (#112)
* fix: upgrade to support 0.76+ * fix: migrate to lite-rt * chore: remove submodule
1 parent bde0f6f commit ccbe815

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ updates:
77
interval: "weekly"
88
labels:
99
- "dependencies"
10-
- package-ecosystem: "gitsubmodule"
11-
directory: "/"
12-
schedule:
13-
interval: "monthly"
14-
labels:
15-
- "dependencies"
1610
# - package-ecosystem: "npm"
1711
# directory: "./"
1812
# schedule:

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "tensorflow"]
2-
path = tensorflow
3-
url = https://github.com/tensorflow/tensorflow

android/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ find_package(fbjni REQUIRED CONFIG)
1111
find_library(
1212
TFLITE
1313
tensorflowlite_jni
14-
PATHS "./src/main/cpp/lib/tensorflow/jni/${ANDROID_ABI}"
14+
PATHS "./src/main/cpp/lib/litert/jni/${ANDROID_ABI}"
1515
NO_DEFAULT_PATH
1616
NO_CMAKE_FIND_ROOT_PATH
1717
)
1818

1919
find_library(
2020
TFLITE_GPU
2121
tensorflowlite_gpu_jni
22-
PATHS "./src/main/cpp/lib/tensorflow/jni/${ANDROID_ABI}"
22+
PATHS "./src/main/cpp/lib/litert/jni/${ANDROID_ABI}"
2323
NO_DEFAULT_PATH
2424
NO_CMAKE_FIND_ROOT_PATH
2525
)
@@ -42,7 +42,7 @@ target_include_directories(
4242
PRIVATE
4343
"../cpp"
4444
"src/main/cpp"
45-
"../tensorflow/"
45+
"src/main/cpp/lib/litert/headers"
4646
"${NODE_MODULES_DIR}/react-native/ReactCommon"
4747
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
4848
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule" # <-- CallInvokerHolder JNI wrapper
@@ -54,8 +54,19 @@ target_link_libraries(
5454
${PACKAGE_NAME}
5555
android # <-- log
5656
ReactAndroid::jsi # <-- jsi.h
57-
ReactAndroid::reactnativejni # <-- CallInvokerImpl
5857
fbjni::fbjni # <-- fbjni.h
5958
${TFLITE}
6059
${TFLITE_GPU}
6160
)
61+
62+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
63+
target_link_libraries(
64+
${PACKAGE_NAME}
65+
ReactAndroid::reactnative # <-- RN merged so
66+
)
67+
else()
68+
target_link_libraries(
69+
${PACKAGE_NAME}
70+
ReactAndroid::reactnativejni # <-- CallInvokerImpl
71+
)
72+
endif()

android/build.gradle

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ android {
8080
"**/libc++_shared.so",
8181
"**/libfbjni.so",
8282
"**/libjsi.so",
83+
"**/libreactnative.so",
8384
"**/libreactnativejni.so",
8485
"**/libturbomodulejsijni.so",
8586
"**/libreact_nativemodule_core.so",
87+
"**/libtensorflowlite_jni.so",
88+
"**/libtensorflowlite_gpu_jni.so",
8689
]
8790
}
8891
buildTypes {
@@ -123,12 +126,28 @@ dependencies {
123126
implementation "com.facebook.react:react-native:+"
124127

125128
// Tensorflow Lite .aar (includes C API via prefabs)
126-
implementation "org.tensorflow:tensorflow-lite:2.16.1"
127-
extractSO("org.tensorflow:tensorflow-lite:2.16.1")
129+
implementation "com.google.ai.edge.litert:litert:1.0.1"
130+
extractSO("com.google.ai.edge.litert:litert:1.0.1")
131+
extractHeaders("com.google.ai.edge.litert:litert:1.0.1")
128132

129133
// Tensorflow Lite GPU delegate
130-
implementation "org.tensorflow:tensorflow-lite-gpu:2.16.1"
131-
extractSO("org.tensorflow:tensorflow-lite-gpu:2.16.1")
134+
implementation "com.google.ai.edge.litert:litert-gpu:1.0.1"
135+
extractSO("com.google.ai.edge.litert:litert-gpu:1.0.1")
136+
extractHeaders("com.google.ai.edge.litert:litert-gpu:1.0.1")
137+
}
138+
139+
task extractAARHeaders {
140+
doLast {
141+
configurations.extractHeaders.files.each {
142+
def file = it.absoluteFile
143+
def packageName = file.name.tokenize('-')[0]
144+
copy {
145+
from zipTree(file)
146+
into "src/main/cpp/lib/$packageName/"
147+
include "**/*.h"
148+
}
149+
}
150+
}
132151
}
133152

134153
task extractSOFiles {
@@ -166,5 +185,6 @@ def nativeBuildDependsOn(dependsOnTask) {
166185
}
167186

168187
afterEvaluate {
188+
nativeBuildDependsOn(extractAARHeaders)
169189
nativeBuildDependsOn(extractSOFiles)
170190
}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"src",
1212
"lib",
1313
"android/src",
14+
"!android/src/main/cpp/lib",
1415
"android/build.gradle",
1516
"android/CMakeLists.txt",
1617
"android/gradle.properties",
@@ -26,14 +27,11 @@
2627
"typecheck": "tsc --noEmit",
2728
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
2829
"lint-cpp": "scripts/clang-format.sh",
29-
"prepare": "git submodule update --init --recursive",
30-
"update-submodule": "git submodule update --remote --merge",
3130
"check-all": "scripts/check-all.sh",
3231
"prepack": "bob build",
3332
"release": "release-it",
3433
"example": "yarn --cwd example",
35-
"configure": "git submodule update --init --recursive && cd tensorflow && ./configure",
36-
"bootstrap": "yarn && yarn example && yarn example pods && yarn configure"
34+
"bootstrap": "yarn && yarn example && yarn example pods"
3735
},
3836
"keywords": [
3937
"react-native",

tensorflow

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)