Search code examples
androidgradletensorflowbuild.gradlebazel

error while building tensorflow on android, using bazel support


As mentioned here in the link below https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#android-studio

"At this point you can add the tensorflow/examples/android directory as a new Android Studio project."

All that I did

  1. Cloned git repo using "git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git"
  2. Built an APK using "bazel build -c opt //tensorflow/examples/android:tensorflow_demo"
  3. Found the APK in "/.../.../tensorflow-master/bazel-bin/tensorflow/examples/android"
  4. As mentioned above, I tried to add "tensorflow/examples/android" directory as a new Android Studio project
  5. As mentioned in the link above "look at build.gradle and make sure that the path to Bazel matches that of your system." I changed it to "def bazelLocation = '/usr/bin/bazel'"

The Error

I am trying to build an APK from the Android Studio and found this error

Error:Execution failed for task ':buildExternalAssets'. Process 'command '/usr/bin/bazel'' finished with non-zero exit value 1

Gradle Build Messages

Executing tasks: [:assembleDebug]

Configuration on demand is an incubating feature.

:preBuild UP-TO-DATE :preDebugBuild UP-TO-DATE :checkDebugManifest :prepareDebugDependencies :compileDebugAidl UP-TO-DATE :compileDebugRenderscript UP-TO-DATE :generateDebugBuildConfig UP-TO-DATE :generateDebugResValues UP-TO-DATE :generateDebugResources UP-TO-DATE :mergeDebugResources UP-TO-DATE :processDebugManifest UP-TO-DATE :processDebugResources UP-TO-DATE :generateDebugSources UP-TO-DATE :incrementalDebugJavaCompilationSafeguard UP-TO-DATE :javaPreCompileDebug :compileDebugJavaWithJavac UP-TO-DATE :compileDebugNdk UP-TO-DATE :compileDebugSources UP-TO-DATE :buildExternalAssets

Couldn't find java at '/usr/local/java/jdk1.8.0_101/bin/java'.

FAILED

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ':buildExternalAssets'.

Process 'command '/usr/bin/bazel'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 11.433 secs


Solution

  • Thanks to @cricket_007 for responding and clearing my concepts about jdk installation

    To solve the issue above

    1. Open "build.gradle" at [/.../.../.../tensorflow-master/tensorflow/examples/android/build.gradle], check for

      "def externalModelData = '../../../bazel-tensorflow-master/external'"

    2. Verify that def externalModelData is pointing to the correct folder name, initially it was '../../../bazel-tensorflow/external'

    3. I had to change it to bazel-tensorflow-master, these are the folders generated by bazel, after you compile the tensorflow sources from github on your command line, using bazel, Android SDK and Android NDK tools

    4. Also make sure that your Jdk installation is perfect.