I'm working on OpenCV library in android studio.I'm using 2.2.1 version of android studio. Problem is that when I run ndk-build.cmd on command prompt, debugger shows that it is not recognised command,operable program or batch file.
when I build my project it gives error, that is:
" Error:(120) *** Android NDK: Aborting. Stop."
I also have tried to build project without importing OpenCV library as I was following a tutorial, but it also give error.
"Error:Execution failed for task ':app:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental."
Even I download CMake and NDK tools but still this error exists. Please guide me to solve this problem.
Thanks in advance.
To run ndk-build
1)you have to add its path in your Enviroment Variable so yo can access it from anywhere with just "ndk-build.cmd"
or
2) you have to give full ndk path like E:\sdk\ndk-bundle\ndk-build.cmd if you have windows
To run ndk-build from command prompt, you can provide the full path to the script, e.g.
C:\> d:\android\ndk\ndk-build.cmd
It is important to install ndk to a directory with no spaces in its full path, e.g.
d:\android SDK\ndk r13
won't work. Avoid spaces in the path to your project, too. Android Studio will not be happy to build
e:\my projects\android apps\ndk sample\build\outputs\apk\my first ndk app.apk
Related
Today I updated my Android Studio NDK to the most recent release 18.0.5002713. After the successful installation process I tried to rerun my app but was not able to do so. The error that keeps appearing is the following: org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
In the past I've already had problems running my app after NDK updates but was able to resolve them by adding arguments '-DANDROID_STL=gnustl_static' to the externalNativeBuild configuration in the app.gradle file.
Original question: (OpenCV - undefined reference to 'cv::CascadeClassifier::detectMultiScale() after NDK update)
By adding this line of code I managed to avoid any sort of problem with the NDK throughout the rest of all NDK r17c releases.
Unfortunately with revision r18 the support for GNUSTL has been removed alongside gabi++ and stlport.
See NDK revision history: https://developer.android.com/ndk/downloads/revision_history
Removing the now deprecated line of code produces the error that originally was the reason for the aforementioned question. The question now is what is the up-to-date equivalent of arguments '-DANDROID_STL=gnustl_static'?
edit: using '-DANDROID_STL=c++_static' leads to the old error
Thank you in advance.
As #Michael already suggested you can rebuild the OpenCV with libc++.
To do it:
cd $OPENCV_SRC
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_DIR/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_ABI="arm64-v8a" -DANDROID_STL=c++_static -DCMAKE_BUILD_TYPE=Release -DANDROID_NATIVE_API_LEVEL=android-24 ..
make install
cd install #the sdk will be here...
NOTE:
tested with "opencv-3.4.1" + ndk18
Edited by #shizhen
Verified on macOS, should add .. after cmake command to make below error disappear.
CMake Error: The source directory "/opencv-3.4.1/build"does not appear to contain CMakeLists.txt.
Updated as below:
cd $OPENCV_SRC
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=$ANDROID_DIR/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_ABI="arm64-v8a" -DANDROID_STL=c++_static -DCMAKE_BUILD_TYPE=Release -DANDROID_NATIVE_API_LEVEL=android-24
make install
cd install #the sdk will be here...
It may take a while for OpenCV to be updated. In the meantime, I would recommend to step back f to NDK r16 which was used to build the OpenCV Android binaries.
first reply to #Aqeel iqbal's comment in the first comment, the reason you cannot find a cmakelist is may because you are not using opencv sources, opencv provide independet package for android sdk. The following ling is the origenal source for opencv sources
opencv release, choose sources to download, not android pack.
After download the sources, cd to the root dir of the source file e.g. opencv-2.4.13.6
then execute the command provided by #y30, and noted the $ANDROID_DIR may not be your correct file path of your android ndk, for me I use these:
...
-DCMAKE_TOOLCHAIN_FILE=/Users/ihandysoft/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake
...
here is armv8a I had generated
https://github.com/2666fff/opencv-for-android
I'm using Android Studio 2.3 beta 3. I put message(AUTHOR_WARNING "Hello CMake, hello Android") In my CMakeLists.txt
But I saw this message only few times when rebuilding project in Android Studio. In most cases there's no "Hello CMake, hello Android" string in Gradle Console after build finishes. I've tried resync gradle and clean/rebuild project, still no expected output.
I have some problems with my build (I think it's incorrect paths) so my goal - to print CMake variables in compile time to better understand what is actually going on.
Inside the project tree, you can find the log with all the cmake output inside the folder of each generated architecture. The relative path to the file should be something like:
[project folder]/app/.externalNativeBuild/cmake/debug/arm64-v8a/cmake_build_output.txt
Here you can see all the MESSAGE calls of the cmake scripts.
my android studio cmake output:
compile detail:
.cxx/cmake/debug/arm64-v8a/compile_commands.json
cmake output:
.cxx/cmake/debug/arm64-v8a/build_output.txt
CMake messages are only at generation time (when CMake is used to generate your project / Makefile).
One way to get CMake to generate is to go to retrieve the build folder and the CMakeCache.txt file in it, and then:
Retrieve the path to your cmake executable, by reading the CMakeCache.txt file and checking the value of the CMAKE_COMMAND variable
Open a command prompt in CMakeCache.txt directory
Run: <path_to_cmake_found_at_point_1> .
Note: The build folder should have a CMakeCache.txt file. The above will not work unless it does.
On my rig I found the logs in <module name>/build/intermediates/cxx/<cmake build type>/<hash>/meta/<ABI>/cmake_server_log.txt -- C++ programming for Android just keeps getting more convenient all the time :\
My rig:
Android Studio Arctic Fox 2020.3.1 Patch 3
AGP 7.0.2
Gradle 7.2.0
NDK 21.4.7075529
CMake 3.10.2
Windows 10 (hopefully host OS doesn't matter)
When i am trying to import a project to my workspace it shows an error
[2013-03-17 16:14:15 - Unable to launch cygpath. Is Cygwin on the
path?] java.io.IOException: Cannot run program "cygpath":
CreateProcess error=2, The system cannot find the file specified
this project contains jni libraries,it is a ndk based project.why this error happen i cant import this project to my system.
go to your project right click there.then take properties and select the c/c++ build and there you can see the build settings .and in the build settings give the path of ndk in your system like:
D:\android\android-ndk-r8d\ndk-build.cmd NDK_DEBUG=1
Now clean your project and run. Thats it.
With NDK r8d, you don't need cygwin. Maybe the project you import was tuned for an older version, and maybe it defined ndk-build.sh as the C++ build command. You should use ndk-build.cmd or simply ndk-build (utilizing Windows command line conventions)
You can set an environment variable
NDK_HOME = [your path to ndk]
Please help, I have a very wierd error here, while I trying to compile project. Console says:
03:17:23 ** Auto Build of configuration Default for project
MyProject * bash ndk-build all make.exe:
C:\workspace/MyProject/build/core/build-local.mk: No such file or
directory make.exe: ** No rule to make target
`C:\workspace/MyProject/build/core/build-local.mk'. Stop.
03:17:24 Build Finished (took 654ms)
So I'm trying compile code from book "Android NDK for Beginnners". First of all, an author telling to convert java project to C++ project. Once I did it - an error appears. To fix it I need to build library with ndk-build , an autor offers to make changes in project properties, exactly go to Builders and change default build command to ndk-build, but thats woun't work without bash word before it. So when I figured that out and tried to build the project - an error occures.
Help please, I can' find the solution.
Your book is probably outdated, or it does not address Windows environment. On Windows, instead of ndk-build command or bash ndk-build, use ndk-build.cmd. Download and ise the latest version of NDK.
I'm adding an android library project to my android app (in this case, Beintoo). It's not mine; It's an external library. However, it doesn't come with a build.xml. Building in Eclipse works fine, but when I attempt to build my app with ant, I get this:
BUILD FAILED
C:\Sandbox\MyProject\build.xml:110: The following error occurred while executing this line:
C:\Sandbox\MyProject\build.xml:41: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:515: Invalid file: C:\Git\Beintoo-Android\beintoo-android-sdk\BeintooSDK\build.xml
It's perfectly true. The file is invalid, because it doesn't exist. I wouldn't know what to do to add it safely, nor if that's even a good idea.
I have learnt that I can't simply build the library project into a jar. How can I get my project to build in Ant with this library project?
Ok, so, Error 454's answer was close, but not quite right. Since r14 of Android Tools, every library project must have it's own build.xml if it is to be built by Ant, as noted here:
https://groups.google.com/forum/?fromgroups#!topic/adt-dev/Z2e3dY-3Ma0
Running android update lib-project (which, as Error 454 notes, is in the android-sdk/tools folder which should be in PATH) on the library project will add a generic build.xml, and allow the main project to build.
For library projects, you need to browse to the library project root and run:
android update lib-project -p .
The android executable is in the android sdk/tools folder which should be added to your path variable in your OS. Once you run this, the necessary build files will be generated and your ant build should succeed.
Similarly, if your root project doesn't have the necessary build files, you will need to browse to the main project root and run:
android update project -p .
Additionally to the two previous correct answers I had to add --target android-16 because I was getting an "Error: The project either has no target set or the target is invalid."
So in my case
android update lib-project -p . --target android-16
Did it. (replace the 16 as you need)