• Home
Name Date Size #Lines LOC

..--

src/main/03-May-2024-7,0094,882

README.mdD03-May-20242.7 KiB5540

build.gradleD03-May-20241.2 KiB5143

download-models.gradleD03-May-20242.4 KiB7967

README.md

1# TF Lite Android App Example
2
3A simple Android example that demonstrates image classification and object
4detection using the camera, as well as speech recognition using the microphone.
5
6## Building in Android Studio with TensorFlow Lite AAR from JCenter.
7The build.gradle is configured to use TensorFlow Lite's nightly build.
8
9If you see a build error related to compatibility with Tensorflow Lite's Java
10API (example: method X is undefined for type Interpreter), there has likely been
11a backwards compatible change to the API. You will need to pull new app code
12that's compatible with the nightly build and may need to first wait a few days
13for our external and internal code to merge.
14
15## Building from Source with Bazel
16
171. Follow the [Bazel steps for the TF Demo App](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#bazel):
18
19  1. [Install Bazel and Android Prerequisites](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#install-bazel-and-android-prerequisites).
20     It's easiest with Android Studio.
21
22      - You'll need at least SDK version 23.
23      - Make sure to install the latest version of Bazel. Some distributions
24        ship with Bazel 0.5.4, which is too old.
25      - Bazel requires Android Build Tools `26.0.1` or higher.
26      - You also need to install the Android Support Repository, available
27        through Android Studio under `Android SDK Manager -> SDK Tools ->
28        Android Support Repository`.
29
30  2. [Edit your `WORKSPACE`](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#edit-workspace)
31     to add SDK and NDK targets.
32
33     NOTE: As long as you have the SDK and NDK installed, the `./configure`
34     script will create these rules for you. Answer "Yes" when the script asks
35     to automatically configure the `./WORKSPACE`.
36
37      - Make sure the `api_level` in `WORKSPACE` is set to an SDK version that
38        you have installed.
39      - By default, Android Studio will install the SDK to `~/Android/Sdk` and
40        the NDK to `~/Android/Sdk/ndk-bundle`.
41
422. Build this demo app with Bazel. The demo needs C++11. We configure the fat_apk_cpu flag to package support for 4 hardware variants. You may replace it with --config=android_arm64 on a 64-bit device and --config=android_arm for 32-bit device:
43
44  ```shell
45  bazel build -c opt --cxxopt='--std=c++11' --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a \
46    //tensorflow/lite/examples/android:tflite_demo
47  ```
48
493. Install the demo on a
50   [debug-enabled device](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#install):
51
52  ```shell
53  adb install bazel-bin/tensorflow/lite/examples/android/tflite_demo.apk
54  ```
55