aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow
diff options
context:
space:
mode:
authorGravatar Andrew Harp <andrewharp@google.com>2017-04-20 11:19:27 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-04-20 12:30:04 -0700
commit4c493e97fe8ac226b8fbf660b25de0efd34807bf (patch)
treea7aafcd4a69fd96f6fe1f2a9aeeab23f79bb88b6 /tensorflow
parent90733a8024532f6993d11f0a89deaecb2bba59fe (diff)
Android: Create TensorFlow AAR as part of nightly build, so that it will be downloadable at https://ci.tensorflow.org/view/Nightly/job/nightly-android/
This contains TensorFlowInferenceInterface and the Java API, as well as all of the native prebuilt libraries. This means that TF can be integrated into an Android Studio app simply by downloading the AAR file to e.g. aar/, and then adding the following into a gradle build file: allprojects { repositories { jcenter() flatDir { dirs 'aar' } } } dependencies { compile(name:'tensorflow', ext:'aar') } Change: 153741338
Diffstat (limited to 'tensorflow')
-rwxr-xr-xtensorflow/tools/ci_build/builds/android_full.sh20
1 files changed, 19 insertions, 1 deletions
diff --git a/tensorflow/tools/ci_build/builds/android_full.sh b/tensorflow/tools/ci_build/builds/android_full.sh
index 407562d4ba..63250e0a4d 100755
--- a/tensorflow/tools/ci_build/builds/android_full.sh
+++ b/tensorflow/tools/ci_build/builds/android_full.sh
@@ -31,8 +31,10 @@ configure_android_workspace
CPUS=armeabi-v7a,arm64-v8a,x86,x86_64
OUT_DIR="$(pwd)/out/"
+AAR_LIB_TMP="$(pwd)/aar_libs"
rm -rf ${OUT_DIR}
+rm -rf ${AAR_LIB_TMP}
# Build all relevant native libraries for each architecture.
for CPU in ${CPUS//,/ }
@@ -50,6 +52,9 @@ do
copy_lib bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so
copy_lib bazel-bin/tensorflow/examples/android/libtensorflow_demo.so
copy_lib bazel-bin/tensorflow/tools/benchmark/benchmark_model
+
+ mkdir -p ${AAR_LIB_TMP}/jni/${CPU}
+ cp bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so ${AAR_LIB_TMP}/jni/${CPU}
done
# Build Jar and also demo containing native libs for all architectures.
@@ -60,12 +65,25 @@ echo "========== Building TensorFlow Android Jar and Demo =========="
bazel --bazelrc=/dev/null build -c opt --fat_apk_cpu=${CPUS} \
--spawn_strategy=sandboxed --genrule_strategy=sandboxed \
//tensorflow/contrib/android:android_tensorflow_inference_java \
+ //tensorflow/contrib/android:android_tensorflow_inference_java.aar \
//tensorflow/examples/android:tensorflow_demo
-echo "Copying demo and Jar to ${OUT_DIR}"
+echo "Copying demo, AAR and Jar to ${OUT_DIR}"
cp bazel-bin/tensorflow/examples/android/tensorflow_demo.apk \
bazel-bin/tensorflow/contrib/android/libandroid_tensorflow_inference_java.jar ${OUT_DIR}
+cp bazel-bin/tensorflow/contrib/android/android_tensorflow_inference_java.aar \
+ ${OUT_DIR}/tensorflow.aar
+
+# TODO(andrewharp): build native libs into AAR directly once
+# https://github.com/bazelbuild/bazel/issues/348 is resolved.
+echo "Adding native libs to AAR"
+chmod +w ${OUT_DIR}/tensorflow.aar
+pushd ${AAR_LIB_TMP}
+zip -ur ${OUT_DIR}/tensorflow.aar $(find jni -name *.so)
+popd
+rm -rf ${AAR_LIB_TMP}
+
# Test Makefile build just to make sure it still works.
if [ -z "$NDK_ROOT" ]; then
export NDK_ROOT=${ANDROID_NDK_HOME}