react-native-fast-tflite icon indicating copy to clipboard operation
react-native-fast-tflite copied to clipboard

Use TensorFlowLiteC from source (`tensorflow/`) on Android as well

Open mrousavy opened this issue 1 year ago • 0 comments

Today, we build TensorFlowLiteC from source to use it in iOS: https://github.com/mrousavy/react-native-fast-tflite/blob/5b8d61270e777dd5b66bbe06004e5109bac8f874/scripts/build-tensorflow-ios.sh#L13-L27

The source code is added to this repo as a git submodule (tensorflow/), and when shipping the library to npm I prebuild a TensorFlowLiteC binary (including the TensorFlowLiteCCoreML delegate), add the headers, then ship it.

On Android however, we use the org.tensorflow:tensorflow-lite library from Gradle: https://github.com/mrousavy/react-native-fast-tflite/blob/5b8d61270e777dd5b66bbe06004e5109bac8f874/android/build.gradle#L125-L128 This ships the Java files as well as introducing some other unnecessary files for the bundle. Also, it is outdated and not in sync with the iOS version, some fixes, features or improvements may only be available on iOS, but not on Android due to us using the published package from Maven. (Currently we use v2.2.0, which is outdated by more than two versions)

Instead, we should aim to also use TensorFlowLiteC (any potentially also an Android GPU delegate?) from source by also building it in the tensorflow/ submodule, just like how we do it on iOS, then add the headers and link the library in the android/CMakeLists.txt config.

This would align the versions perfectly and we don't need to fetch a prebuild version from Maven.

This PR was an attempt at doing so: https://github.com/mrousavy/react-native-fast-tflite/pull/33 ...but I couldn't manage to get Bazel to build the Android version.

We need to make sure this ships the correct binaries (x86, x86_64, arm, and arm64 - or just x86_fat and arm_fat).


Added Bonus: Maybe we can even do the whole building in the CI with dependabot, so everytime the submodule changes (a commit lands on main in tensorflow/) it opens a PR, prebuilds the libraries, moves them into ios and android, and I only need to merge that to get the changes. No need to build it on my mac. Makes it even more safe

mrousavy avatar Jan 31 '24 15:01 mrousavy