Auto-fetch Inception model assets for Android demo, so that manual download/extract step is unnecessary.
Change: 138475677
diff --git a/WORKSPACE b/WORKSPACE
index f96dbef..0634cd5 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -463,3 +463,10 @@
   name = "weblas_weblas_js",
   url = "https://raw.githubusercontent.com/waylonflinn/weblas/v0.9.0/dist/weblas.js",
 )
+
+new_http_archive(
+  name = "inception5h",
+  build_file = "models.BUILD",
+  url = "https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip",
+  sha256 = "d13569f6a98159de37e92e9c8ec4dae8f674fbf475f69fe6199b514f756d4364"
+)
diff --git a/models.BUILD b/models.BUILD
new file mode 100644
index 0000000..7c3e5a0
--- /dev/null
+++ b/models.BUILD
@@ -0,0 +1,13 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])  # Apache 2.0
+
+filegroup(
+    name = "model_files",
+    srcs = glob(
+        [
+            "**/*.pb",
+            "**/*.txt",
+        ],
+    ),
+)
diff --git a/tensorflow/examples/android/BUILD b/tensorflow/examples/android/BUILD
index 3e44487..4fd4365 100644
--- a/tensorflow/examples/android/BUILD
+++ b/tensorflow/examples/android/BUILD
@@ -58,8 +58,13 @@
     ]) + [
         "//tensorflow/contrib/android:android_tensorflow_inference_java_srcs",
     ],
-    assets = glob(["assets/**"]),
-    assets_dir = "assets",
+    # Package assets from assets dir as well as all model targets. Remove undesired models
+    # (and corresponding Activities in source) to reduce APK size.
+    assets = [
+        "//tensorflow/examples/android/assets:asset_files",
+        "@inception5h//:model_files",
+    ],
+    assets_dir = "",
     custom_package = "org.tensorflow.demo",
     inline_constants = 1,
     manifest = "AndroidManifest.xml",
diff --git a/tensorflow/examples/android/README.md b/tensorflow/examples/android/README.md
index 50a6351..b0465f7 100644
--- a/tensorflow/examples/android/README.md
+++ b/tensorflow/examples/android/README.md
@@ -26,8 +26,13 @@
 be reported.
 
 The TensorFlow `GraphDef` that contains the model definition and weights
-is not packaged in the repo because of its size. Instead, you must
-first download the file to the `assets` directory in the source tree:
+is not packaged in the repo because of its size. It will be downloaded
+automatically via a new_http_archive defined in WORKSPACE.
+
+**Optional**: If you wish to place the model in your assets manually (E.g. for
+non-Bazel builds), remove the
+`inception_5` entry in `BUILD` and download the archive yourself to the
+`assets` directory in the source tree:
 
 ```bash
 $ curl -L https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip -o /tmp/inception5h.zip
@@ -38,8 +43,8 @@
 The labels file describing the possible classification will also be in the
 assets directory.
 
-Then, after editing your WORKSPACE file, you must build the APK. Run this from
-your workspace root:
+After editing your WORKSPACE file to update the SDK/NDK configuration,
+you may build the APK. Run this from your workspace root:
 
 ```bash
 $ bazel build //tensorflow/examples/android:tensorflow_demo
diff --git a/tensorflow/examples/android/assets/BUILD b/tensorflow/examples/android/assets/BUILD
new file mode 100644
index 0000000..c827de7
--- /dev/null
+++ b/tensorflow/examples/android/assets/BUILD
@@ -0,0 +1,15 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])  # Apache 2.0
+
+# It is necessary to use this filegroup rather than globbing the files in this
+# folder directly the examples/android:tensorflow_demo target due to the fact
+# that assets_dir is necessarily set to "" there (to allow using other
+# arbitrary targets as assets).
+filegroup(
+    name = "asset_files",
+    srcs = glob(
+        ["**/*"],
+        exclude = ["BUILD"],
+    ),
+)
diff --git a/tensorflow/tools/ci_build/builds/android.sh b/tensorflow/tools/ci_build/builds/android.sh
index bb90d09..2e40e70 100755
--- a/tensorflow/tools/ci_build/builds/android.sh
+++ b/tensorflow/tools/ci_build/builds/android.sh
@@ -16,16 +16,6 @@
 
 set -e
 
-# Download model file.
-# Note: This is workaround. This should be done by bazel.
-model_file_name="inception5h.zip"
-tmp_model_file_name="${HOME}/.cache/tensorflow_models/${model_file_name}"
-mkdir -p $(dirname ${tmp_model_file_name})
-[ -e "${tmp_model_file_name}" ] || wget -c "https://storage.googleapis.com/download.tensorflow.org/models/${model_file_name}" -O "${tmp_model_file_name}"
-# We clean up after ourselves, but not if we exit with an error, so make sure we start clean
-rm -rf tensorflow/examples/android/assets/
-unzip -o "${tmp_model_file_name}" -d tensorflow/examples/android/assets/
-
 # Modify the WORKSPACE file.
 # Note: This is workaround. This should be done by bazel.
 if grep -q '^android_sdk_repository' WORKSPACE && grep -q '^android_ndk_repository' WORKSPACE; then