When following TF Lite documentation for building the C++ shared libraries to use their APIs on Android apps , I experienced many Bazel build errors. After searching on the internet for a while, this solution worked for me (on both my local Mac and Linux Google Colab). This repo shows the instructions to build the libraries, specifically every commands that can be executed sequentially to get the job done!
If you don't care about the process, just go ahead and get the generated libraries (for 32bit armeabi-v7a and 64bit arm64-v8a) in the folder generated-libs.
- Install Bazel via Homebrew:
brew install bazel
- Clone the TensorFlow repo
git clone https://github.com/tensorflow/tensorflow
cd tensorflow/
- Build the libraries
# For ARM 64 bit
bazel build -c opt //tensorflow/lite:libtensorflowlite.so --fat_apk_cpu=arm64-v8a
# For ARM 32 bit
bazel build -c opt //tensorflow/lite:libtensorflowlite.so --fat_apk_cpu=arm-v7a
Notice how the build commands are different from TF Lite guides:
--config=android_arm64
and --config=android_arm
are replaced by --fat_apk_cpu=arm64-v8a
and --fat_apk_cpu=arm-v7a
, respectively.
The generated library would be saved at ./bazel-bin/tensorflow/lite/libtensorflowlite.so
.
Almost similar, except for installing Bazel (a little more complicated). For more details, please check out the notebook run_me.ipynb.
If you find this repo useful, please give it a star!