NDK - problems after GNUSTL has been removed from the NDK (revision r18) - android

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

Related

Facing this error The following binaries are missing: ndk-build. Please install them

I'm trying to build ' linphone-android ' .
link to git repo
Somehow i manged to resolv all the bugs but now i'm stuck at when i try to run ' ./prepare.py **' commanad in terminal it giving me NDK ERROR i.e **ERROR: The following binaries are missing: ndk-build. Please install them.
I have ndk path in .bash file also but unable to resolve this error.
Please share some solution
Thanks :)
I am assuming that you have added android-sdk and android-ndk path in your environment. If not then you can add sdk and ndk path using below command.
export PATH=/Users/kaushik512/Library/Android/sdk/platform-tools/:/Users/kaushik512/Library/Android/sdk/tools/:/Users/kaushik512/Downloads/android-ndk-r12b/:/nobackup/local/prog/nasm/bin:$PATH
export PATH=/opt/local/bin/:$PATH
after adding path check using echo $PATH.
Add above in PATH and see if issue resolved.
Do check the version of ndk in your android studio. I was facing the same problem and my ndk version was 16 so I changed it to 15 it worked but also I made the project again and followed the steps one by one as given in the repository, the same link that you have provided.
Hope that helps.

ndk-build.cmd isn't recognized as internal or external command

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

Android Studio, CMake. How to print debug message in compile time?

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)

How to use the build boost libraries in android ndk after building it

I have built the boost libraries after downloading it. Now if I right click on the Project-> Properties-> C/C++ general -> Paths and symbols and add the $(NDK_PATH)/boost,
the files get recognized before building it but when I try to build I get unresolved error. Note that I do not make the Android.mk file in the boost library as shown here
because I include it in the paths and symbols. Is it wrong??
I followed the step Igor told me in my previous comment
Using Boost in android ndk with windows.
I do not have any $ANDROID_NDK/sources/boost/android folder as pointed in the codeexperiments link.. Is anything wrong?
I am using the following command:
b2 --without-python --without-serialization threading=multi link=static runtime-link=static toolset=gcc-android target-os=linux --stagedir=android stage
The error I get is:
notice: could not find main target stage notice: assuming it is a name of file to create. don't know how to make <e>stage ...found 1 target... ...can't find 1 target...
Android ndk: r8e
Env: Windows 64 bit
Eclipse: Juno 4.2.1

Adding android library project to an android project prevents Ant from building

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)

Categories

Resources