Android: Adds import of model assets into build.gradle via bazel
This should be enough to get the Android examples working directly through Android Studio, that is: check out the GitHub repo, set up bazel location, load build.gradle in AS and run. Change: 149609160
This commit is contained in:
parent
e8c6631e2b
commit
5b3e560d2f
@ -69,9 +69,7 @@ android_binary(
|
||||
# (and corresponding Activities in source) to reduce APK size.
|
||||
assets = [
|
||||
"//tensorflow/examples/android/assets:asset_files",
|
||||
"@inception5h//:model_files",
|
||||
"@mobile_multibox//:model_files",
|
||||
"@stylize//:model_files",
|
||||
":external_assets",
|
||||
],
|
||||
assets_dir = "",
|
||||
custom_package = "org.tensorflow.demo",
|
||||
@ -88,6 +86,15 @@ android_binary(
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "external_assets",
|
||||
srcs = [
|
||||
"@inception5h//:model_files",
|
||||
"@mobile_multibox//:model_files",
|
||||
"@stylize//:model_files",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all_files",
|
||||
srcs = glob(
|
||||
|
@ -41,6 +41,9 @@ if (buildWithMake) {
|
||||
// automatically.
|
||||
def makeNdkRoot = System.getenv('NDK_ROOT')
|
||||
|
||||
// Location of model files required as assets
|
||||
def externalModelData = '../../../bazel-tensorflow/external'
|
||||
|
||||
// If building with Bazel, this is the location of the bazel binary.
|
||||
// NOTE: Bazel does not yet support building for Android on Windows,
|
||||
// so in this case the Makefile build must be used as described above.
|
||||
@ -124,6 +127,11 @@ task buildNativeMake(type: Exec) {
|
||||
//, '-T' // Uncomment to skip protobuf and speed up subsequent builds.
|
||||
}
|
||||
|
||||
task buildExternalAssets(type: Exec) {
|
||||
commandLine bazelLocation, 'build', '//tensorflow/examples/android:external_assets'
|
||||
outputs.files(externalModelData)
|
||||
}
|
||||
|
||||
task copyNativeLibs(type: Copy) {
|
||||
from demoLibPath
|
||||
from inferenceLibPath
|
||||
@ -133,7 +141,22 @@ task copyNativeLibs(type: Copy) {
|
||||
fileMode 0644
|
||||
}
|
||||
|
||||
assemble.dependsOn copyNativeLibs
|
||||
afterEvaluate {
|
||||
assembleDebug.dependsOn copyNativeLibs
|
||||
task copyExternalAssets(type: Copy) {
|
||||
from file(externalModelData).listFiles()
|
||||
include '*.pb'
|
||||
include '*.txt'
|
||||
include 'thumbnails/*.jpg'
|
||||
into 'assets'
|
||||
fileMode 0644
|
||||
dependsOn buildExternalAssets
|
||||
}
|
||||
|
||||
def copyTasks = [copyNativeLibs]
|
||||
if (!buildWithMake) {
|
||||
// copyExternalAssets uses bazel, so only run it when requested.
|
||||
copyTasks.add(copyExternalAssets)
|
||||
}
|
||||
assemble.dependsOn copyTasks
|
||||
afterEvaluate {
|
||||
assembleDebug.dependsOn copyTasks
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user