I want to use andengine in my android studio project but I have ndk error while building.
Error:Execution failed for task ':andEngine:compileReleaseNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\Android\android-ndk-r9d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\Android.mk APP_PLATFORM=android-19 NDK_OUT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\obj NDK_LIBS_OUT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\lib APP_ABI=all
Error Code:
2
Output:
D:/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\obj/local/armeabi-v7a/objs/andengine_shared/D_\Android\workspace\simpleclock\simple_clock_as\andEngine\src\main\jni\src\GLES20Fix.o: in function Java_org_andengine_opengl_GLES20Fix_glVertexAttribPointer:GLES20Fix.c(.text.Java_org_andengine_opengl_GLES20Fix_glVertexAttribPointer+0x40): error: undefined reference to 'glVertexAttribPointer'
D:/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\obj/local/armeabi-v7a/objs/andengine_shared/D_\Android\workspace\simpleclock\simple_clock_as\andEngine\src\main\jni\src\GLES20Fix.o: in function Java_org_andengine_opengl_GLES20Fix_glDrawElements:GLES20Fix.c(.text.Java_org_andengine_opengl_GLES20Fix_glDrawElements+0x30): error: undefined reference to 'glDrawElements'
collect2: ld returned 1 exit status
make.exe: *** [D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\obj/local/armeabi-v7a/libandengine_shared.so] Error 1
I suppose I'm missing some OpenGL files?
The Android Gradle plugin's NDK task does not actually use any Android.mk file that you may have provided in your jni/ folder. This was a great source of confusion for me until I figured that out.
It generates a intermediate Android.mk file during the build, based on parameters that you have set in your Gradle build script and on the content of your jni/ folder.
You can see this for yourself by inspecting the source for its NdkCompile task at https://android.googlesource.com/platform/tools/base/+/55aebda607efcc29b8d9d5e1a99d446e320ff288/build-system/gradle/src/main/groovy/com/android/build/gradle/tasks/NdkCompile.groovy.
Note the writeMakeFile(...) method on line 126.
This is why the error you are getting from the ndk-build command that runs as part of your Gradle build references the build script APP_BUILD_SCRIPT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\Android.mk, not something like APP_BUILD_SCRIPT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\src\main\jni\Android.mk as you might expect and want it to.
There is no way of getting the Android Gradle plugin's NDK task to use your own Android.mk file (believe me if there was I would have found it!).
You have two options for getting your NDK code compiling as part of Gradle:
Figure out the correct configuration to put in your build.gradle so that the generated Android.mk file contains the required LOCAL_LDLIBS := -lGLESv2 line and any of the other lines from https://github.com/nicolasgramlich/AndEngine/blob/GLES2/jni/Android.mk that are required.
Write a custom NDK compile task that uses the AndEnginge's Android.mk file directly. I've recently had to do this myself for an NDK source set that requires more parameters than the Android Gradle plugin currently supports passing via Gradle, so it if comes to this I can provide help.
I think in this case option 1 is open and so of course the preferable solution.
Something like this added to the android defaultConfig block should work:
android {
defaultConfig {
ndk {
moduleName "myNDKModule"
stl "stlport_shared"
ldLibs "lGLESv2"
cFlags "-Werror"
}
}
}
Unfortunately I am very much not a C/native code expert (I know practically nothing) so cannot guess whether AndEngine needs LOCAL_MODULE_FILENAME and LOCAL_EXPORT_C_INCLUDES to be set to build correctly. If it does, you'll need to go with approach 2 (at least until if/when the Android Gradle NDK task supports configuring them). Though I have just checked out the AndEngine git repo and successfully run ndk-build after having removed them from its Android.mk file, which is promising.
(I found which NDK properties can be parametrised via inspection of https://android.googlesource.com/platform/tools/base/+/55aebda607efcc29b8d9d5e1a99d446e320ff288/build-system/gradle/src/main/groovy/com/android/build/gradle/internal/dsl/NdkConfigDsl.java).
I had a similar issue, and this video https://www.youtube.com/watch?v=0-rYK2oh8oo helped me to fix the build issues. Basically, you need to download (and extract) NDK from here: http://developer.android.com/ndk/downloads/index.html and specify the NDK location in Module Settings. Also, you need to alter the andEngine's build.gradle file to include
sourceSets{
main{
jni.srcDirs = []
}
}
Android.mk actually includes the line?
https://github.com/nicolasgramlich/AndEngine/blob/GLES2/jni/Android.mk#L10
LOCAL_LDLIBS := -lGLESv2
These errors indicate it.
error: undefined reference to 'glVertexAttribPointer'
error: undefined reference to 'glDrawElements'
Related
How do I get a verbose log (including the command-line arguments to compiler and linker) when building with Android Studio?
I have just transitioned from Ant / Android.mk builds to Android-Studio builds.
With the old system, I was able to see how the compiler was evoked by doing:
$ ndk-build V=1
What would be the equivalent setting in Android Studio to accomplish this?
I have a suspicion that my project is building against the wrong GLES version (gles2 instead of gles3) and want to make sure by seeing the command line arguments to the linker.
It turns out you can make the build verbose by changing the build.gradle file as follows:
externalNativeBuild {
cmake {
arguments "-DCMAKE_VERBOSE_MAKEFILE=1"
}
}
When using ndk-build instead of cmake, use this instead:
externalNativeBuild {
ndkBuild {
arguments "V=1"
}
}
Regarding to https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/NdkBuild there is no possibility to pass arguments.
But you can pass an the folder for outputs, which generates .json files
externalNativeBuild {
ndkBuild {
// Tells Gradle to put outputs from external native
// builds in the path specified below.
buildStagingDirectory "./outputs/ndk-build"
path 'Android.mk'
}
}
So in my case in outputs/ndk-build/debug/json_generation_record.json the last "message" told me the error:
JSON generation completed with problem. Exception: Build command failed.
Error while executing process .... ndk-build.cmd ....
...
Android.mk:myLib-prebuilt: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that ... exists or that its path is correct
...prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.\n"
I have an application in packages/apps under my vendor dir in Android O.
The application relies on a HIDL interface, which is added as a java library.
If I build the app with Android.mk file, it builds just fine.
If I build the app with Android.bp file, hiding the Android.mk, it doesn't build and fails with an error:
ninja: error: unknown target 'MODULES-IN-vendor-${vendor_name}-apps-${app_name}', did you mean 'MODULES-IN-vendor-${vendor_name}-apps-${another_app_name}'?
Or it can be just
ninja: error: unknown target 'MODULES-IN-vendor-${vendor_name}-apps-${app_name}'
My Android.bp looks like:
android_app {
java_libs: ["some.hidl.lib-V1.0-java"],
java_static_libs: ["android.hidl.base-V1.0-java-static"],
srcs: ["**/*.java"],
android_resource_dirs: ["res/**"],
name: "MyApplication",
module_name: "MyApplication",
package_name: "me.myself.MyApplication", // also tried just the name as it is done in Android.mk
enabled: true,
proguard_enabled: disabled
}
Any ideas?
Not sure if you have resolved this issue, I also met such issue. This is caused by Android only tries to include the "Android.bp" file from the level 3 folder which is defined in "Android.bp" under root folder:
optional_subdirs = [
....
"vendor/*/*",
]
So you need to add one "Android.bp" into vendor/vendor_name/packages with specified optional_subdirs or just wildcard as above.
In my case, I was using Android.mk file only but by mistake I used arm64 in
LOCAL_MODULE_TARGET_ARCH := arm64
But I was building for x86_64 target. So I changed to
LOCAL_MODULE_TARGET_ARCH := x86_64
And I worked. Might be this answer is not directly related to it but If someone would have done same mistake then it would help.
I'm trying to get C++ code to work with react-native (see this for the general steps).
I've generated my project with react-native init, generated the JNI bindings by using Djinni. I'm now trying to build the application and test it on my android emulator (cd $PROJECT_ROOT/android && ./gradlew installDebug). It seems like the header files aren't found, their directories aren't included :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
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.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:6:10: fatal error: 'cpp_bridge_text.hpp' file not found
#include "cpp_bridge_text.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
I managed to get past this small issue by creating hard links to the headers causing issues. Which leads me to this :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
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.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:7:
$PROJECT_ROOT/app/src/main/jni/djinni_support.hpp:20:10: fatal error: 'exception' file not found
#include <exception>
^~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
In this case, it seems like even standard libraries aren't included.
My question is : how do I explicitly specify gradle to add directories to its search/indlude path?
In regular Android projects, it seems that you can edit Android.mk/Application.mk files. There aren't such files in my folders ; I think that gradle actually generates an Android.mk file (in $PROJECT_ROOT/android/app/build/intermediates/ndk/debug/Android.mk), I tried editing it (LOCAL_C_INCLUDES field) to add my directories, but it gets overwritten when I try another build.
Thanks in advance.
You can edit this in $PROJECTROOT/android/app/build.gradle :
android {
defaultConfig {
(...)
ndk {
(...)
cFlags = "-Ipath/to/directory/"
}
}
}
However, you will most likely encounter other issues (I know that for a fact, because I did). I'd recommend you to use the modern and user-friendly CMake integration.
I'm gonna write down the general steps so that I can find it again sometime in the future :
Add your files to the android project (under android studio or another IDE). There should be files in your java/ folder, files in your jni/ folder (JNI bridge files), and files in your cpp/ folder (the native C++).
Add a CMakeLists.txt file to your module (usually named app if you're using react-native).
In this file, respect the following structure :
cmake_minimum_required(VERSION 3.4.1)
add_library( # Name of the library
$(YOUR_LIBRARY_NAME)
# Sets it as a shared library
SHARED
# Relative path to the source file(s)
path/to/your/file.cpp path/to/other/file.cpp )
# Allows you to add folders to the search path : similar to -Ipath/to/your/headerfolder/
include_directories(path/to/your/headerfolder/)
# Allows you to have special compilation flags for the specified library's compilation
target_compile_options( $(YOUR_LIBRARY_NAME)
PRIVATE # You can also use PUBLIC/INTERFACE
-std=gnu++11 ) # Your option ; I needed this in my case
Once it's done, you need to link gradle to your native library :
If you're using android studio, just use the information available in this guide as it's very well explained.
If you aren't, I also advise you to check out this guide, because it's really well explained.
After that, you can either build the project in android studio, or cd $(PROJECTROOT)/android && ./gradlew installDebug. It should work.
Good luck!
I am new to using an ndk and was trying to use some of the sample projects that came in the android ndk10d folder. For example the hello-jni sample project. I keep getting this error:
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Jonathon\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-21 NDK_OUT=C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\lib APP_ABI=all
Error Code: 2 Output:
make.exe: *** No rule to make target `C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/hello-jni/C_\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\src\main\jni', needed by `C:\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/hello-jni/C_\Users\Jonathon\AndroidStudioProjects\hello-jni2\app\src\main\jni\hello-jni.o'. Stop.
I have checked and the file: ndk-build.cmd is indeed in the location specified. When I try to open it command prompt says that it cannot find the application project directory. Please define the NDK_PROJECT_PATH variable to it
I re-installed and updated my whole environment from 0.8.9 to android studio 0.9.9 and now 1.01 and I get the same error. It seems it can't find the file or file directory and that must mean my configuration isn't right but I can't determine what to do to fix it.
local.properties
sdk.dir=C\:\\Users\\Jonathon\\AppData\\Local\\Android\\sdk
ndk.dir=C\:\\Users\\Jonathon\\android-ndk-r10d
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
Check out this video for building simple NDK projects with Android studio
https://www.youtube.com/watch?v=kFtxo7rr2HQ&list=UUkbLy9aj5IBXfS6WqLy5Qmw
Alternatively you can also download Intel Native Developer Experience tool that comes with the NDK plugin for Android Studio
You can remove the Android.mk file: it will be ignored as a new one is generated on the fly from your gradle configuration (build.gradle file). You can get more information on this from my article on NDK support in Android Studio.
The bug you're experiencing is this one: https://code.google.com/p/android/issues/detail?id=66937&
A simple workaround is to create a empty .c file next to hello-jni.c.
If you have only one .c (or .cpp) file add a dummy .c (or .cpp) file and it works.
I'm trying to debug .so library, using NDK for Android.
I'm able to build .so library, using ndk-build. But when I want to debug my library,
I set ndk-build NDK_DEBUG = 1 and receive following error: make: * empty variable name. Stop.
And also I receive the error: Unable to launch cygpath. Is Cygwin on the path?
Appreciate any help, thanks
You must remove the spaces in the assignment, ie
ndk-build NDK_DEBUG=1
rather than
ndk-build NDK_DEBUG = 1