1# Android TensorFlow support 2 3This directory defines components (a native `.so` library and a Java JAR) 4geared towards supporting TensorFlow on Android. This includes: 5 6- The [TensorFlow Java API](../../java/README.md) 7- A `TensorFlowInferenceInterface` class that provides a smaller API 8 surface suitable for inference and summarizing performance of model execution. 9 10For example usage, see [TensorFlowImageClassifier.java](../../examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java) 11in the [TensorFlow Android Demo](../../examples/android). 12 13For prebuilt libraries, see the 14[nightly Android build artifacts](https://ci.tensorflow.org/view/Nightly/job/nightly-android/) 15page for a recent build. 16 17The TensorFlow Inference Interface is also available as a 18[JCenter package](https://bintray.com/google/tensorflow/tensorflow) 19(see the tensorflow-android directory) and can be included quite simply in your 20android project with a couple of lines in the project's `build.gradle` file: 21 22``` 23allprojects { 24 repositories { 25 jcenter() 26 } 27} 28 29dependencies { 30 compile 'org.tensorflow:tensorflow-android:+' 31} 32``` 33 34This will tell Gradle to use the 35[latest version](https://bintray.com/google/tensorflow/tensorflow/_latestVersion) 36of the TensorFlow AAR that has been released to 37[JCenter](https://jcenter.bintray.com/org/tensorflow/tensorflow-android/). 38You may replace the `+` with an explicit version label if you wish to 39use a specific release of TensorFlow in your app. 40 41To build the libraries yourself (if, for example, you want to support custom 42TensorFlow operators), pick your preferred approach below: 43 44### Bazel 45 46First follow the Bazel setup instructions described in 47[tensorflow/examples/android/README.md](../../examples/android/README.md) 48 49Then, to build the native TF library: 50 51``` 52bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so \ 53 --crosstool_top=//external:android/crosstool \ 54 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ 55 --cxxopt=-std=c++11 \ 56 --cpu=armeabi-v7a 57``` 58 59Replacing `armeabi-v7a` with your desired target architecture. 60 61The library will be located at: 62 63``` 64bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so 65``` 66 67To build the Java counterpart: 68 69``` 70bazel build //tensorflow/contrib/android:android_tensorflow_inference_java 71``` 72 73You will find the JAR file at: 74 75``` 76bazel-bin/tensorflow/contrib/android/libandroid_tensorflow_inference_java.jar 77``` 78 79### CMake 80 81For documentation on building a self-contained AAR file with cmake, see 82[tensorflow/contrib/android/cmake](cmake). 83 84 85### Makefile 86 87For documentation on building native TF libraries with make, including a CUDA-enabled variant for devices like the Nvidia Shield TV, see [tensorflow/contrib/makefile/README.md](../makefile/README.md) 88 89 90## AssetManagerFileSystem 91 92This directory also contains a TensorFlow filesystem supporting the Android 93asset manager. This may be useful when writing native (C++) code that is tightly 94coupled with TensorFlow. For typical usage, the library above will be 95sufficient. 96