Skip to content

Build shared libraries (`.so`) to use TF Lite C++ API in Android applications

License

Notifications You must be signed in to change notification settings

cuongvng/TF-Lite-Cpp-API-for-Android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate shared libraries (.so) for using TF Lite C++ API in Android applications

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.

On Mac OS

brew install bazel
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.

On Linux

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!