the android tensorflow demo build error with bazel command - android

when i run the tensorflow android demo.
i have installed the bazel for a long time to build the environment.
and then when all tool is done.then run the demo in Android Studio.
the gradle console show me this:
the error image
and the error occured when the task of buildNative executed.
the full command line display in the gradle console:
Starting process 'command '/usr/local/bin/bazel''. Working directory: /Users/colarking/Workspace/tensorflow Command: /usr/local/bin/bazel build -c opt tensorflow/examples/android:tensorflow_native_libs --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --verbose_failures --host_crosstool_top=#bazel_tools//tools/cpp:toolchain
Successfully started process 'command '/usr/local/bin/bazel''

Did you build native libs with these commands?
CPU=armeabi-v7a
bazel build //tensorflow/examples/android:tensorflow_native_libs --crosstool_top=//external:android/crosstool --cpu=$CPU --host_crosstool_top=#bazel_tools//tools/cpp:toolchain
NATIVE_FOLDER=tensorflow/examples/android/libs/$CPU
mkdir -p $NATIVE_FOLDER
cp bazel-bin/tensorflow/examples/android/libtensorflow_demo.so $NATIVE_FOLDER
Source: https://github.com/tensorflow/tensorflow/issues/3444

Tensorflow cannot see the path to the NDK. You need to update the WORKSPACE file in the projects root folder with the NDK and sdk paths. you also need to install the correct NDK for your machine. Follow the instructions here

Related

I am not able to build .so file

I am trying to make an app for object detection using tensorflow and I am following the instructions as listed in this website:
https://www.skcript.com/svr/realtime-object-and-face-detection-in-android-using-tensorflow-object-detection-api/
But I have run into build errors.
I am making an android application for detecting objects using tensorflow API and I have followed all steps as mentioned in the above link. I am using Windows 10 for coding, not any Linux distro. I tried building the app using bazel but there are build errors.
Here's the command as instructed from the above website:
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
After running, it starts compiling and does 1069 processes, but after reaching 1068/1069 it displays the following:
ERROR: C:/sri/sritrain/tensorflow-master/tensorflow/contrib/android/BUILD:60:1: Linking of rule '//tensorflow/contrib/android:libtensorflow_inference.so' failed (Exit 1)
external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: fatal error: bazel-out/armeabi-v7a-opt/bin/tensorflow/core/kernels/libandroid_tensorflow_kernels.lo: pread failed: Invalid argument
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
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: 3148.512s, Critical Path: 443.26s
INFO: 1045 processes: 1045 local.
FAILED: Build did NOT complete successfully
I scoured through the internet and found a small modification so I typed:
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 --cxxopt=-std=c++11
However this returns an error even before the previous command did:
ERROR: C:/sri/sritrain/tensorflow/tensorflow/contrib/android/BUILD:60:1: Linking of rule '//tensorflow/contrib/android:libtensorflow_inference.so' failed (Exit 1)
external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: fatal error: bazel-out/armeabi-v7a-opt/bin/tensorflow/core/kernels/libandroid_tensorflow_kernels.lo: pread failed: Invalid argument
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
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: 2787.155s, Critical Path: 244.57s
INFO: 795 processes: 795 local.
FAILED: Build did NOT complete successfully
It is supposed to create a .so file on my computer but it doesn't.
I SOLVED IT!
I found the problem was that i was using the ndk-bundle from under Android Studio's folder and it was the latest ndk. I downloaded an older ndk version android_ndk_r15c and ran the 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 --cxxopt=-std=c++11
So the build was completed successfully!

Building Tensorflow

I want to build tensorflow for my android smartphone. So I´ve installed bazel and get the sources for tensorflow.
git clone https://github.com/tensorflow/tensorflow
I modify the WORKSPACE file with my paths for the NDK and the SDK
android_sdk_repository(
name = "androidsdk",
api_level = 27,
build_tools_version = "27.0.3",
# Replace with path to Android SDK on your system
path = ".../AppData/Local/Android/Sdk",
)
android_ndk_repository(
name = "androidndk",
path = .../AppData/Local/Android/Sdk/ndk-bundle",
api_level = 27
)
And now I run bazel
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
And got this error
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 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: 72,096s, Critical Path: 14,55s
INFO: 213 processes, local.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
How can I compile tensorflow for android with windows (or maybe ubuntu)?

Compiling React Native project with local fork - NDK_PROJECT_PATH

I'm trying to compile my React Native Android project using a local fork of react-native. I've followed the building from source guide and completed all steps (not using Android Studio).
When I try to run react-native run-android (from project root as normal), I get:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ReactAndroid:buildReactNdkLib'.
> Process 'command '/usr/local/opt/android-ndk/ndk-build'' finished with non-zero exit value 2
When I run ndk-build (from project root), I get:
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/usr/local/Cellar/android-ndk/r12b/build/core/build-local.mk:151: *** Android NDK: Aborting . Stop.
Another SO thread pointed me in the direction of running ndk-build from ./android/app/src and create a jni directory there (I didn't have one), but I'm unsure how to obtain or create jni/Android.mk correctly or if this will even help me. I've tried creating jni/Application.mk with contents APP_BUILD_SCRIPT := Android.mk and jni/Android.mk with the setup described in that SO question. Running ndk-build from android/app/src exits with the following error:
Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: Android.mk
/usr/local/Cellar/android-ndk/r12b/build/core/add-application.mk:198: *** Android NDK: Aborting... . Stop.
I have the Android SDK and NDK installed with Homebrew and I have the following exports:
ANDROID_HOME=/usr/local/opt/android-sdk
ANDROID_SDK=/usr/local/opt/android-sdk
ANDROID_NDK=/usr/local/opt/android-ndk
ANDROID_NDK_HOME=/usr/local/opt/android-ndk
I feel like I'm close, but have no idea how to continue.
I think the issue is with android-ndk version. We need to use ndk version specified by react-native documentation. I tried with the latest version of andrid-ndk. I was not able to build the project, got similar error while running react-native run-android.
Then I tried with android-ndk-r10e version. It worked fine, I was able to build the project successfully.
Also you may find this react-native github issue discussion useful.
I'm trying to compile React Native UIExplorer for Android.And I have same issue.
Then I run ndk-build ,I get:
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/usr/local/Cellar/android-ndk/r13b/build/core/build-local.mk:151: *** Android NDK: Aborting . Stop.
My android-ndk version is /android-ndk/r13b/,So I download android-ndk-r10e .
I use the most direct way:
$ cd /usr/local/Cellar/android-ndk/r13b
$ rm -rf ./*
$ mv YourUnZipPath/android-ndk-r10e/* ./
Then It worked fine, I was able to build the project successfully.

tensorflow build fails with “BUILD file not found on package”

I trying build tensorflow_demo for android with Bazel, but I get this error:
ERROR: no such package 'tensorflow/tensorflow/examples/android': BUILD file not found on package path.
I have build file in directory (MacOS):
/Users/pavelgosteev/tensorflow/tensorflow/examples/android
build command:
(tensorflow) MBP-Pavel:tensorflow pavelgosteev$ bazel build //tensorflow/tensorflow/examples/android:tensorflow_demo
What's wrong? Why can't Bazel see build file?
I think you need one fewer "tensorflow" in the build target name. Try:
bazel build //tensorflow/examples/android:tensorflow_demo
Further instructions can be found in the Tensorflow Android tutorial.

mobile App with ionic

hello
I am trying to build hybrid app with ionic and cordova
at first i run below commands and they run successfully
but after running the last command i get this error
ionic start firtApp
cd firtApp
ionic platform add android
note: it return me android-21 error, and i changed the android-21 to android-18, and it runs successfully
ionic build android
after running the above command i got this error
BUILD FAILED
D:\New folder\android-sdk-final\android-sdk-fully\sdk\tools\ant\build.xml:601: T
he following error occurred while executing this line:
D:\New folder\android-sdk-final\android-sdk-fully\sdk\tools\ant\build.xml:542: U
nable to resolve project target 'android-21'
Total time: 1 second
C:\Users\Mohammad\firstapp\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "ant debug -f C:\Users\Mohammad\f
irstapp\platforms\android\build.xml -Dout.dir=ant-build -Dgen.absolute.dir=ant-g
en"
ERROR building one of the platforms: Error: C:\Users\Mohammad\firstapp\platforms
\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: C:\Users\Mohammad\firstapp\platforms\android\cordova\build.bat: Command f
ailed with exit code 8
at ChildProcess.whenDone (C:\Users\Mohammad\AppData\Roaming\npm\node_modules
\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
please help me with this error
i really like to bulid hybrid apps with my web knowledge
thanks.
You can try this
Go to this directory
C:\Users\Mohammad\.cordova\lib\npm_cache\cordova-android\3.6.4\package\framework
Edit project.properties file. Change target to 19.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-19
apk-configurations=
renderscript.opt.level=O0
android.library=true
Restart your terminal.
You don't have SDK correctly installed on you computer. (Path or SDK update)
It's write on your error log : You may not have the required environment or OS to build this project
you just need to install ant
sudo apt-get install ant
then do the same as before,its work correctly

Categories

Resources