Join us in person and online for Firebase Summit on October 18, 2022. Learn how Firebase can help you accelerate app development, release your app with confidence, and scale with ease. Register now

Use a custom TensorFlow Lite build

Stay organized with collections Save and categorize content based on your preferences.

If you're an experienced ML developer and the pre-built TensorFlow Lite library doesn't meet your needs, you can use a custom TensorFlow Lite build with ML Kit. For example, you may want to add custom ops.


Bundling a custom TensorFlow Lite for Android

Build the Tensorflow Lite AAR:

bazel build --cxxopt='--std=c++11' -c opt        \
  --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a   \

This will generate an AAR file in bazel-genfiles/tensorflow/lite/java/. Publish the custom Tensorflow Lite AAR to your local Maven repository:

mvn install:install-file -Dfile=bazel-genfiles/tensorflow/lite/java/tensorflow-lite.aar -DgroupId=org.tensorflow \
  -DartifactId=tensorflow-lite -Dversion=0.1.100 -Dpackaging=aar

Finally, in your app build.gradle, override Tensorflow Lite with your custom version:

implementation 'org.tensorflow:tensorflow-lite:0.1.100'