Skip to content

Instantly share code, notes, and snippets.

@lelayf
Last active June 18, 2018 15:58
Show Gist options
  • Save lelayf/c8a974982ea3f279b4049ea75952cd5d to your computer and use it in GitHub Desktop.
Save lelayf/c8a974982ea3f279b4049ea75952cd5d to your computer and use it in GitHub Desktop.
Build TensorFlow Lite demo for Android
#!/bin/sh
cd ~
# install bazel if you don't have it already
brew install bazel
# install Android NDK v14b in your home dir (more recent versions are NOT supported by Bazel)
# check https://developer.android.com/ndk/downloads/older_releases
curl -O https://dl.google.com/android/repository/android-ndk-r14b-darwin-x86_64.zip
unzip android-ndk-r14b-darwin-x86_64.zip
# clone tensorflow repo
git clone https://github.com/tensorflow/tensorflow.git
# the WORKSPACE file in tensorflow used to have PATHs for Android SDK and NDK
# this is not the case anymore and you can use environment variables instead
export ANDROID_BUILD_TOOLS_VERSION="26.0.1"
export ANDROID_NDK_API_LEVEL="21"
export ANDROID_NDK_HOME="$HOME/android-ndk-r14b"
export ANDROID_SDK_API_LEVEL="23"
export ANDROID_SDK_HOME="$HOME/Library/Android/sdk"
export ANDROID_SDK_LEVEL="23"
# now build the demo
cd tensorflow
bazel build -c opt --cxxopt='--std=c++11' //tensorflow/contrib/lite/examples/android:tflite_demo
# success? Great! now add Android Debugging Bridge to your PATH
export PATH="$ANDROID_SDK_HOME/platform-tools/":$PATH
# plug your phone over USB and allow debugging from the pop-up dialog
# note: you could create an emulator or use a wifi connection to the phone
# but I did not try those options.
#
# check that your device is listed and that it does not say "unauthorized"
adb devices
# install APK
adb install bazel-bin/tensorflow/contrib/lite/examples/android/tflite_demo.apk
# success? great now you should see 3 apps installed :
# TFLClassifier, TFLDetection, TFLSpeech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment