From 1f5b09112ce4aec45d612ba7e70ce3e611f209b5 Mon Sep 17 00:00:00 2001 From: bang9 Date: Sun, 24 Nov 2024 04:42:23 +0900 Subject: [PATCH 1/3] fix: upgrade to support 0.76+ --- android/CMakeLists.txt | 13 ++++++++++++- android/build.gradle | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index b603d830e..5d7c235a5 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -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() diff --git a/android/build.gradle b/android/build.gradle index 43fc45567..cce35974a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -80,6 +80,7 @@ android { "**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", + "**/libreactnative.so", "**/libreactnativejni.so", "**/libturbomodulejsijni.so", "**/libreact_nativemodule_core.so", From a9a353f19e6fdf817ed895d7e56cb1154d4a3d00 Mon Sep 17 00:00:00 2001 From: bang9 Date: Sun, 24 Nov 2024 05:28:06 +0900 Subject: [PATCH 2/3] fix: migrate to lite-rt --- android/CMakeLists.txt | 6 +++--- android/build.gradle | 27 +++++++++++++++++++++++---- package.json | 1 + 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 5d7c235a5..100468cfc 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -11,7 +11,7 @@ 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 ) @@ -19,7 +19,7 @@ find_library( 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 ) @@ -42,7 +42,7 @@ target_include_directories( PRIVATE "../cpp" "src/main/cpp" - "../tensorflow/" + "src/main/cpp/lib/litert/headers" "${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 diff --git a/android/build.gradle b/android/build.gradle index cce35974a..0083618ed 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -84,6 +84,8 @@ android { "**/libreactnativejni.so", "**/libturbomodulejsijni.so", "**/libreact_nativemodule_core.so", + "**/libtensorflowlite_jni.so", + "**/libtensorflowlite_gpu_jni.so", ] } buildTypes { @@ -124,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 { @@ -167,5 +185,6 @@ def nativeBuildDependsOn(dependsOnTask) { } afterEvaluate { + nativeBuildDependsOn(extractAARHeaders) nativeBuildDependsOn(extractSOFiles) } diff --git a/package.json b/package.json index 2afa1fcbb..6e85312b9 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "src", "lib", "android/src", + "!android/src/main/cpp/lib", "android/build.gradle", "android/CMakeLists.txt", "android/gradle.properties", From 5807fd9bbac861da4051c81654bd7687471395d6 Mon Sep 17 00:00:00 2001 From: bang9 Date: Sun, 24 Nov 2024 05:45:52 +0900 Subject: [PATCH 3/3] chore: remove submodule --- .github/dependabot.yml | 6 ------ .gitmodules | 3 --- package.json | 5 +---- tensorflow | 1 - 4 files changed, 1 insertion(+), 14 deletions(-) delete mode 160000 tensorflow diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 94dc21319..ab81d3a7a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,12 +7,6 @@ updates: interval: "weekly" labels: - "dependencies" - - package-ecosystem: "gitsubmodule" - directory: "/" - schedule: - interval: "monthly" - labels: - - "dependencies" # - package-ecosystem: "npm" # directory: "./" # schedule: diff --git a/.gitmodules b/.gitmodules index 53e0a1359..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "tensorflow"] - path = tensorflow - url = https://github.com/tensorflow/tensorflow diff --git a/package.json b/package.json index 6e85312b9..b8407d2df 100644 --- a/package.json +++ b/package.json @@ -27,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", diff --git a/tensorflow b/tensorflow deleted file mode 160000 index e960f13b7..000000000 --- a/tensorflow +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e960f13b7e55133b51ffc91ebcafe06a17260fa6