• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TF Lite Android Image Classifier App Example
2
3A simple Android example that demonstrates image classification using the camera.
4
5## Building in Android Studio with TensorFlow Lite AAR from MavenCentral.
6The build.gradle is configured to use TensorFlow Lite's nightly build.
7
8If you see a build error related to compatibility with Tensorflow Lite's Java API (example: method X is
9undefined for type Interpreter), there has likely been a backwards compatible
10change to the API. You will need to pull new app code that's compatible with the
11nightly build and may need to first wait a few days for our external and internal
12code to merge.
13
14## Building from Source with Bazel
15
161. Follow the [Bazel steps for the TF Demo App](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#bazel):
17
18  1. [Install Bazel and Android Prerequisites](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#install-bazel-and-android-prerequisites).
19     It's easiest with Android Studio.
20
21      - You'll need at least SDK version 23.
22      - Make sure to install the latest version of Bazel. Some distributions
23        ship with Bazel 0.5.4, which is too old.
24      - Bazel requires Android Build Tools `28.0.0` or higher.
25      - You also need to install the Android Support Repository, available
26        through Android Studio under `Android SDK Manager -> SDK Tools ->
27        Android Support Repository`.
28
29  2. [Edit your `WORKSPACE`](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#edit-workspace)
30     to add SDK and NDK targets.
31
32     NOTE: As long as you have the SDK and NDK installed, the `./configure`
33     script will create these rules for you. Answer "Yes" when the script asks
34     to automatically configure the `./WORKSPACE`.
35
36      - Make sure the `api_level` in `WORKSPACE` is set to an SDK version that
37        you have installed.
38      - By default, Android Studio will install the SDK to `~/Android/Sdk` and
39        the NDK to `~/Android/Sdk/ndk-bundle`.
40
412. Build the app with Bazel. The demo needs C++11:
42
43  ```shell
44  bazel build -c opt //tensorflow/lite/java/demo/app/src/main:TfLiteCameraDemo
45  ```
46
473. Install the demo on a
48   [debug-enabled device](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#install):
49
50  ```shell
51  adb install bazel-bin/tensorflow/lite/java/demo/app/src/main/TfLiteCameraDemo.apk
52  ```
53