Repository navigation
Description
What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?
#6101
#6383
http://stackoverflow.com/questions/40978859/creating-simple-android-app-using-android-studio-and-tensorflow
Environment info
Operating System: Windows
Installed version of CUDA and cuDNN:
(please attach the output of ls -l /path/to/cuda/lib/libcud*):
Cuda 8.0
cuDNN 5.0
If installed from source, provide
-
The commit hash (
git rev-parse HEAD)
I downloaded the latest ZIP on 18 Dec 2016. Sorry, I have no idea how to get the version. -
The output of
bazel version
Build label: 0.4.2
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Dec 7 18:47:13 2016 (1481136433)
Build timestamp: 1481136433
Build timestamp as int: 1481136433
My goal is to build an Android App which loads pre-trained TensorFlow model and runs it on an Android device. I am working on Android Studio on Windows. Unfortunately using Android Studio on Linux is currently not an option.
Following previous advice from this forum, I am trying to build an Android example using Bazel on Windows.
I've successfully installed Bazel using Chocolatey.
Following the build instructions, I changed the SDK and NDK paths in WORKSPACE file and ran:
bazel build //tensorflow/examples/android:tensorflow_demo
So far I did the following to fix errors:
- copied aapt.exe to aapt, zipalign.exe to zipalign, since their name is different on Windows/Linux
- installed using pacman gcc
But I am stuck again. I am getting the following error which I have no idea how to fix:
ERROR: C:/Users/Andrey/AppData/Local/Temp/_bazel_Andrey/gd3-gSwg/external/protobuf/BUILD:73:1: C++ compilation of rule '@protobuf//:protobuf_lite' failed: arm-linux-androideabi-gcc failed: error executing command external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc -fstack-protector-strong -fpic -ffunction-sections -funwind-tables ... (remaining 44 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
external/protobuf/src/google/protobuf/stubs/structurally_valid.cc:588:1: fatal error: opening dependency file bazel-out/android-arm-linux-androideabi-4.9-v7a-gnu-libstdcpp-fastbuild/bin/external/protobuf/_objs/protobuf_lite/external/protobuf/src/google/protobuf/stubs/structurally_valid.d: No such file or directory
} // namespace google
^
compilation terminated.
ERROR: C:/Tools/tensorflow-master/tensorflow/examples/android/BUILD:58:1: output 'tensorflow/examples/android/tensorflow_demo_symbols/R.txt' was not created.
ERROR: C:/Tools/tensorflow-master/tensorflow/examples/android/BUILD:58:1: output 'tensorflow/examples/android/tensorflow_demo.srcjar' was not created.
ERROR: C:/Tools/tensorflow-master/tensorflow/examples/android/BUILD:58:1: output 'tensorflow/examples/android/proguard/tensorflow_demo/_tensorflow_demo_proguard.cfg' was not created.
ERROR: C:/Tools/tensorflow-master/tensorflow/examples/android/BUILD:58:1: output 'tensorflow/examples/android/tensorflow_demo_processed_manifest/AndroidManifest.xml' was not created.
ERROR: C:/Tools/tensorflow-master/tensorflow/examples/android/BUILD:58:1: output 'tensorflow/examples/android/tensorflow_demo_files/resource_files.zip' was not created.
ERROR: C:/Tools/tensorflow-master/tensorflow/examples/android/BUILD:58:1: output 'tensorflow/examples/android/tensorflow_demo.ap_' was not created.
ERROR: C:/Users/Andrey/AppData/Local/Temp/_bazel_Andrey/gd3-gSwg/external/protobuf/BUILD:73:1: output 'external/protobuf/_objs/protobuf_lite/external/protobuf/src/google/protobuf/stubs/stringprintf.o' was not created.
ERROR: C:/Users/Andrey/AppData/Local/Temp/_bazel_Andrey/gd3-gSwg/external/protobuf/BUILD:73:1: output 'external/protobuf/_objs/protobuf_lite/external/protobuf/src/google/protobuf/arenastring.o' was not created.
ERROR: C:/Users/Andrey/AppData/Local/Temp/_bazel_Andrey/gd3-gSwg/external/protobuf/BUILD:113:1: output 'external/protobuf/_objs/protobuf/external/protobuf/src/google/protobuf/io/strtod.o' was not created.
ERROR: C:/Users/Andrey/AppData/Local/Temp/_bazel_Andrey/gd3-gSwg/external/protobuf/BUILD:73:1: output 'external/protobuf/_objs/protobuf_lite/external/protobuf/src/google/protobuf/repeated_field.o' was not created.
Target //tensorflow/examples/android:tensorflow_demo failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4.722s, Critical Path: 1.16s
- Please advice how to proceed?
- Isn't there an easier way to achieve what I want? I just need pre-built TensorFlow binaries for Android Studio on Windows, to build an example application. So far I found only pre-built Python distribution and Bazel installation on Windows
Activity
aselle commentedon Dec 20, 2016
@petewarden, you mentioned you have had experience with android builds on windows.
AndreyRub commentedon Dec 22, 2016
Ok, after trying to build the Bazel example Android project on Linux, and reverse engineering the .apk package, it looks like it depends only on a single .so native TensorFlow Android library, called libtensorflow_demo.so.
Currently in order to build this simple example on Windows, I needed to:
... That is a very hard and tedious process
I think that it could really help if there was an example Android Studio project for windows which does not use Bazel at all. Instead let's put the mentioned above pre-compiled TensorFlow library available for download (for all possible Android architectures - arm64-v8a, armeabi, armeabi-v7a ,x86_64) ,together with a simple tutorial.
Obviously, it will not be as flexible as the ability to re-build TensorFlow, but for 99% of users it will suffice to update the pre-built libraries once in a while.
andrewharp commentedon Dec 22, 2016
Unfortunately Bazel doesn't support Android on Windows yet.
However we do have cmake support in tensorflow/contrib/android/cmake that should let you build the library necessary for simple Android inference on Windows (this excludes some native code created specifically for the demo). Full demo support should be coming soon, possibly including pre-built libs.
As a sort-of-hacky alternative you can grab the APK built by Jenkins here, and unzip it to grab libtensorflow_demo.so to manually place into your project.
andrewharp commentedon Jan 9, 2017
@AndreyRub Please see http://ci.tensorflow.org/view/Nightly/job/nightly-android/ for a full selection of prebuilt Android TF libs, which has just come online.
You can either download libtensorflow_inference.so for something that can be dropped into a standalone app, or grab
libtensorflow_demo.so if you're trying to get the TF Android demo to run (contains libtensorflow_inference.so + demo-specific native code).
In either case you will need libandroid_tensorflow_inference_java.jar as well for the Java counterpart.
bulatyauheni commentedon Feb 7, 2017
@andrewharp or @AndreyRub Could you please provide some steps for such goal:
In order to build simple example on Windows with retrained model, I needed to:
I am really stuck with it. Thank you.
andrewharp commentedon Feb 7, 2017
@bulatyauheni Bazel does not support Android on Windows yet. You might try the cmake build, but easiest thing to do if you just want to plug something into your Android Studio project is to grab the pre-built libraries referenced above.
Anmolk22 commentedon Feb 27, 2017
@andrewharp Hey Andrew I am trying to build tensorflow/examples/android on windows 7 using Android Studio. Is it possible or not ?

And even if I can build it can you look into this error if possible
I also tried to write another commandLine 'export JAVA_HOME="$(ls -d C:/Program\ Files/Java/jdk* | sort | tail -n 1)"' but even this didn't work
36 remaining items
Android demo: Add YUV -> RGB conversion Java implementation as fallba…
Android demo: Allow DetectorActivity to gracefully degrade if no nati…
andrewharp commentedon May 5, 2017
Another update: libtensorflow_demo.so is now (as soon as the above commits get pushed to master) an optional library. If not present, YUV->RGB color conversion will be performed in Java (possibly slower), and object tracking will be disabled in the TF Detect demo, but otherwise things will work as usual.
This means the demo can be built on Windows with just the prebuilt tensorflow.aar dropped into your project folder. We're in the process of uploading this to jcenter, at which point it will only take a couple of lines of Gradle config to add a TF dep to Android projects.
Full cmake support for building TF is also still on the roadmap (no timeline for this yet though).
andrewharp commentedon May 8, 2017
The AAR build of TF is now live! This is labeled 1.2.0 preview, but note that this is merely to indicate it comes between 1.1.0 and 1.2.0 (the 1.2.0 release branch has not even been cut yet). We'll be updating it on every point release going forward.
You can enable it in your Android app by adding the following to build.gradle:
For the official TF demo, you'll also want to remove the following to prevent redundant Java classes from being included:
And remove the reference to the locally-built inference lib as well:
from inferenceLibPathIf using an arm64 device, change cpuType from armeabi-v7a to arm64-v8 (since you'll need libtensorflow_demo.so to be built at the highest architecture target your device can use that the AAR provides libtensorflow_inference.so at).
If using bazel to build, change the following in buildNativeBazel:
'tensorflow/examples/android:tensorflow_native_libs'->'tensorflow/examples/android:libtensorflow_demo.so'and if using make, change the following in buildNativeMake:
'libtensorflow_inference.so libtensorflow_demo.so'->'libtensorflow_demo.so'Once fd69bb2 and efa08d8 are pushed to master (which will make libtensorflow_demo.so an optional lib), you could also just remove the native lib dependencies altogether.
We'll be cleaning this up to make it easier to switch soon, and also add a cmake build for libtensorflow_demo.so
jubjamie commentedon May 24, 2017
Hi @andrewharp Just tried to follow some of the advice in here to get this running on Windows. I've found that by far the easiest method was to just download the nightly binaries and stick them in. I tried to use your above method to use the aar but I got an error saying that the compile method was not available. Seemed to suggest it was a gradle issue. Either way I couldn't fix and resorted to sticking the prebuilts in. Not sure if you've come across this?
On another note, this thread has lots of good information and is more detailed than the documentation. Are there plans to get the documentation up to spec to contain all this information? It's slightly unclear atm, especially regarding Windows. I did notice that you said some progress was being made. Thanks for your help.
andrewharp commentedon May 24, 2017
@jubjamie Can you paste the exact error message please? Haven't seen that one before.
The README.md files have recently been updated with AAR instructions, and I'm working on a detailed getting started guide that will cover all of the approaches to building and integrating TensorFlow into apps.
jubjamie commentedon May 24, 2017
@andrewharp I've got around the error so not able to get it up again I don't think. It seems to be a common error within android so i've put a very similar message below. Most solutions appear to suggest removing the compile line however that's for those specific stack overflow situations. Here it's not so simple.
In my scenario I obviously had gradle installed etc. I noticed that in the latest release there is another compile call at the very end of build.gradle which it didn't pick up on (but I wonder if that is because it didn't get that far?). This was using android on Windows 10.
I was about to open another issue regarding performance of the android app using custom tensorflow for poets models (takes 5 times as long) but not sure it's really a bug or a stack overflow question. Can I email you? Otherwise I can open a stack overflow and paste the link here? @petewarden here too perhaps?
andrewharp commentedon May 24, 2017
@jubjamie Ok -- I assume this sort of thing can be cleared up in Android Studio by just clicking to install/upgrade whatever Gradle-related thing it asks you to? Or were you building from the command line?
Re Inception: the performance of v3 (from the TF for Poets guide) is known to be slower than v1 (aka 5h, bundled with the demo). It's a much larger model so some difference is expected. Speeding it up is more of a Stack Overflow topic, but if you're interested you might try seeing what ops are taking up the most time on your device with tensorflow/tools/benchmark:benchmark_model.
petewarden commentedon Jul 12, 2017
As a note on performance, I've recently updated the TensorFlow for Poets script with the option to save out MobileNet models, which can be a lot smaller and faster than the default Inception v3, at the cost of some accuracy:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/tutorials/image_retraining.md#other-model-architectures
It looks like the original issue is fixed, or at least obsolete now though? I'm closing this for the moment, please reopen with more information if that's incorrect.
SimianRainbow commentedon Dec 12, 2017
The link referring to the AAR build is now giving a 404. Has the link for this windows build method now changed?
darrinps commentedon Apr 19, 2018
So still no Windows support after a year when this issue was first brought up? Just tried to build the demo.
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':buildNativeBazel'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at
...
Caused by: java.io.IOException: Cannot run program "/usr/local/bin/bazel" (in directory "C:\GitProjects\tensorflow"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 10 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 11 more
komputerboy commentedon Aug 28, 2018
there still no bazel support on windows, you can use cmake, but still its performance still no guarantee though
nickcuypers commentedon Oct 24, 2018
Hey guys, I am trying to include some experimental operators located in the contrib folders(tensor_forest) to a tensorflow build so that I can load a tensorflow model in my xamarin.android project using these operators without an error that states that the operators are not recognized.
In order to do this I thought I started with trying to build tensorflow android throught this command:
bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cxxopt=-std=c++11 --cpu=armeabi-v7a --verbose_failuresBut I keep getting these kinds of errors
ERROR: C:/users/cuypeni/_bazel_cuypeni/jumq43mw/external/com_google_absl/absl/numeric/BUILD.bazel:25:1: C++ compilation of rule '@com_google_absl//absl/numeric:int128' failed (Exit -1). Note: Remote connection/protocol failed with: execution failed: clang failed: error executing command cd C:/users/cuypeni/_bazel_cuypeni/jumq43mw/execroot/org_tensorflow SET PATH=C:\msys64\usr\bin;C:\msys64\bin;C:\Users\cuypeni\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\cuypeni\bin;C:\Program Files\Anaconda3;C:\Program Files\Anaconda3\Library\mingw-w64\bin;C:\Program Files\Anaconda3\Library\usr\bin;C:\Program Files\Anaconda3\Library\bin;C:\Program Files\Anaconda3\Scripts;C:\Python37\Scripts;C:\Python37;C:\Program Files\Docker\Docker\Resources\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Shoreline Communications\ShoreWare Client;C:\Program Files\nodejs;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Users\cuypeni\AppData\Local\Microsoft\WindowsApps;C:\Users\cuypeni\AppData\Roaming\npm;C:\Users\cuypeni\AppData\Local\Programs\Microsoft VS Code\bin;C:\ProgramData\chocolatey\lib\msys2;C:\msys64\usr\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl SET PWD=/proc/self/cwd SET PYTHON_BIN_PATH=C:/Program Files/Anaconda3/python.exe SET PYTHON_LIB_PATH=C:/Program Files/Anaconda3/lib/site-packages SET TF_DOWNLOAD_CLANG=0 SET TF_NEED_CUDA=0 SET TF_NEED_OPENCL_SYCL=0 SET TF_NEED_ROCM=0 external/androidndk/ndk/toolchains/llvm/prebuilt/windows-x86_64/bin/clang -D__ANDROID_API__=14 -isystemexternal/androidndk/ndk/sysroot/usr/include/arm-linux-androideabi -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -gcc-toolchain external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -mthumb -Os -g -DNDEBUG -MD -MF bazel-out/armeabi-v7a-opt/bin/external/com_google_absl/absl/numeric/_objs/int128/int128.d -frandom-seed=bazel-out/armeabi-v7a-opt/bin/external/com_google_absl/absl/numeric/_objs/int128/int128.o -D__CLANG_SUPPORT_DYN_ANNOTATION__ -iquote external/com_google_absl -iquote bazel-out/armeabi-v7a-opt/genfiles/external/com_google_absl -iquote bazel-out/armeabi-v7a-opt/bin/external/com_google_absl -iquote external/bazel_tools -iquote bazel-out/armeabi-v7a-opt/genfiles/external/bazel_tools -iquote bazel-out/armeabi-v7a-opt/bin/external/bazel_tools -w -std=c++11 -Wall -Wextra -Wcast-qual -Wconversion-null -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wunused-local-typedefs -Wunused-result -Wvarargs -Wvla -Wwrite-strings -Wno-sign-compare --sysroot=external/androidndk/ndk/platforms/android-14/arch-arm -isystem external/androidndk/ndk/sources/cxx-stl/llvm-libc++/include -isystem external/androidndk/ndk/sources/cxx-stl/llvm-libc++abi/include -isystem external/androidndk/ndk/sources/android/support/include -isystemexternal/androidndk/ndk/sysroot/usr/include -c external/com_google_absl/absl/numeric/int128.cc -o bazel-out/armeabi-v7a-opt/bin/external/com_google_absl/absl/numeric/_objs/int128/int128.o Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(239): CreateProcessW("C:\users\cuypeni\_bazel_cuypeni\jumq43mw\execroot\org_tensorflow\external\androidndk\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\clang" -D__ANDROID_API__=14 -isystemexternal/androidndk/ndk/sysroot/usr/include/arm-linux-androideabi -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -gcc-toolchain external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -mthumb -Os -g -DNDEBUG -MD -MF bazel-out/armeabi-v7a-opt/bin/external/com_google_absl/absl/numeric/_objs/int128/int128.d -frandom-seed=bazel-out/armeabi-v7a-opt/bin/external/com_google_absl/absl/numeric/_objs/int128/int128.o -D__CLANG_SUPPORT_DYN_ANNOTATION__ -iquote external/com_google_absl -iquote bazel-out/armeabi-v7a-opt/genfiles/external/com_google_absl -iquote bazel-out/armeabi-v7a-opt/bin/external/com_google_absl -iquote external/bazel_tools -iquote bazel-out/armeabi-v7a-opt/genfiles/external/bazel_tools -iquote bazel-out/armeabi-v7a-opt/bin/external/bazel_tools -w -std=c++11 -Wall -Wextra -Wcast-qual -Wconversion-null -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wunused-local-typedefs -Wunused-result -Wvarargs -Wvla -Wwrite-strings -Wno-sign-compare --sysroot=external/androidndk/ndk/platforms/android-14/arch-arm -isystem external/androidndk/ndk/sources/cxx-stl/llvm-libc++/include -isystem external/androidndk/ndk/sources/cxx-stl/llvm-libc++abi/include -isystem external/androidndk/ndk/sources/android/support/include -isystemexternal/androidndk/ndk/sysroot/usr/include -c external/com_google_absl/absl/numeric/int128.cc -o bazel-out/armeabi-v7a-opt/bin/external/com_google_absl/absl/numeric/_objs/int128/int128.o): The system cannot find the file specified.Is there still no bazel support for windows?
Please some help I'm stuck on this ...
cusitkhan commentedon Oct 24, 2018
Anmolk22 hi can you please tell how you should build libtensorflow_infrence.so file
i am using this command bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a but it give me error
ERROR: C:/users/sabir-pc/_bazel_sabir-pc/zp6kp3ov/external/com_google_absl/absl/strings/BUILD.bazel:32:1: C++ compilation of rule '@com_google_absl//absl/strings:strings' failed (Exit 1)
In file included from external/com_google_absl/absl/strings/str_cat.cc:15:
In file included from external/com_google_absl\absl/strings/str_cat.h:62:
In file included from external/com_google_absl\absl/strings/numbers.h:37:
In file included from external/com_google_absl\absl/numeric/int128.h:29:
In file included from external/androidndk/ndk/sources/cxx-stl/llvm-libc++/include\cmath:305:
In file included from external/androidndk/ndk/sources/android/support/include\math.h:32
3 errors generated.
Target //tensorflow/contrib/android:libtensorflow_inference.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 212.615s, Critical Path: 18.57s
INFO: 213 processes: 213 local.
FAILED: Build did NOT complete successfully