Used software:
Visual Studio 2012 Express
cocos2d-x 2.0-x-2.0.4
cygwin 1.7.5.
Eclipse 3.8
Android SDK last
Android NDK r8c
I am new in development for Android, so don't understand what is wrong.
Trying to build cocs2d-x standart testcpp project.
First trouble was when when i runned create-android-project.bat - it didn't shows target versions of Android (target - v.2.3.3.), but all paths are correct.
At last it build project folder. But next step - building pack in cygwin - fails in case of hundreds of "file or folder not exists" errors of headers, didn't uses a lot of STL headers and ask for <string.h> but not just <string>.
What am i doing wrong?
set NDK path in build_native.sh file in android project folder, then excute build_native.sh by using cygwin
You must rename APPNAME variable in build_native.sh same to your eclipse project name
try to update android-NDK, I have same error using NDK-r8d, and try to execute build-native script too.
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)
I have been trying endlessly to build the sample HelloJni sample project for the Android NDK.
How I set up the environment:
I followed the instructions of the getting started in the docs: android-ndk-r10d\docs\Getting_Started/html/index.html:
Downloaded Eclipse Luna
Downloaded the Android SDK
Downloaded the Android NDK: android-ndk-r10d
Set the NDK installation folder in eclipse in preferences window -> android -> NDK.
Imported the hellp-jni sample.
Right click on the HelloJni Project -> Android tools -> Add native support.
Cleaned and Built the project.
Ran on my device the HelloJni library (not the tests)
And the app is running and everything is WORKING and I can see the generated .so file per architecture in the libs folder of the project (for every architecture, for example armebi, mips, etc...)
Here is a Print Screen showing everything is working:
Now here comes the strange part...
The Problem:
If I open the hello-jni.c file for editing or viewing in eclipse, I suddenly see compilation errors and I can't build and can't run the project anymore...
Here is a Print Screen showing that after i open the file, I suddenly get compilation errors:
What I have already tried but failed:
Adding the Android Native Nature, then removing it by:
Deleting the .project file,
the buildCommand tag of: org.eclipse.cdt.managedbuilder.core.genmakebuilde,
the buildCommand tag of: org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
and removing the lines:
[nature]org.eclipse.cdt.core.cnature[/nature]
[nature]org.eclipse.cdt.core.ccnature[/nature] [nature]org.eclipse.cdt.managedbuilder.core.managedBuildNature[/nature] [nature]org.eclipse.cdt.managedbuilder.core.ScannerConfigNature[/nature]
removing the .cproject and all compiled files.
Then adding back the Android Native Nature.
According to this stackoverflow link:
Eclipse ADT - Unresolved inclusion jni.h
Failed
Once I got the error of (I am not getting it anymore): Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath". So I Googled and I changed the build settings to give the absolute path of my NDK installation folder:
According to this stackoverflow link:
Unable to launch cygpath in android
Here is a Print Screen:
Failed
Changing the Used tools from Android GCC Compiler to GCC C Compiler
according to this stackoverflow link:
Android NDK build, Method could not be resolved
Here is a Print Screen:
Failed
Copying an eclipse Luna installation from a friend that has the project working for him.
Failed
I have been spending hours on this and I couldn't find any solution to why this is happening.
PLEASE HELP
This is a common problem when you try to edit a C/C++ file inside a JAVA workspace/perspective without the proper configuration. You can simply select all the entries in the Error Log and delete them.
FWIW, Eclipse seems to have issues with the r10d version of Android NDK. See https://code.google.com/p/android/issues/detail?id=97023. I suggest you try r10c instead #worksforme :)
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)
I try to import example projects using Android NDK 7 into Eclipse.
The problem is that no matter how I do it. The project always ends up being completely empty.
For example I tried to import the hello-jni example.
I have both tried to import it via:
New -> Project -> Android Project -> Create project from existing source
Import -> Existing Projects into Workspace
Both times the computer seems to find the AndroidManifest.xml as it correctly fills out the fields for package name, etc. But as soon as I press Finish I only have an empty project.
The same procedure works for Android Projects not using the NDK as e.g. the Snake example from Android SDK. The behaviour is also consistent between MacOSX Lion and Windows.
What do I need to import the existing Android NDK examples into Eclipse.
NOTE: I managed to import the projects, when I copy the ndk into the root directory. However in the NDK documentation it says I can put in into any directory I want and I would rather not have it in the root directory. Any ideas why it only works there?
You can compile in eclipse though, In Short :-
This assumes you can compile from command line, i.e. you have ndk-build on your path so you can call ndk-build from command line.
This works on in Helios Version: Helios Service Release 2.
Download the CDT plugin for Eclipse for starters, i presume you know how to get plugins into Eclipse. its under LANGUAGES , install all non incubation plugins for C/C++.
Create your Android Java project (or import the example project), add your JNI folder and also your Android.mk in this directory.
Go FILE / NEW / OTHER
Then if CDT is installed correctly Under C/C++ / ( Convert to a C/C++ Project )
Check the project, choose MakeFile Project and Other Toolchain click NEXT
Next go PROJECT / PROPERTIES / C/C++ uncheck " use default build command" replace "make" with "ndk-build"
This works for me :)
Probably you don't have .so file. Use cygwin and ndk-build to create it. In jni folder you have .mk file