andengine compileReleaseNdk error

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:Androidandroid-ndk-r9dndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaseAndroid.mk APP_PLATFORM=android-19 NDK_OUT=D:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaseobj NDK_LIBS_OUT=D:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaselib 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:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaseobj/local/armeabi-v7a/objs/andengine_shared/D_Androidworkspacesimpleclocksimple_clock_asandEnginesrcmainjnisrcGLES20Fix.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:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaseobj/local/armeabi-v7a/objs/andengine_shared/D_Androidworkspacesimpleclocksimple_clock_asandEnginesrcmainjnisrcGLES20Fix.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:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaseobj/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:Androidworkspacesimpleclocksimple_clock_asandEnginebuildintermediatesndkreleaseAndroid.mk , not something like APP_BUILD_SCRIPT=D:Androidworkspacesimpleclocksimple_clock_asandEnginesrcmainjniAndroid.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'
    
    链接地址: http://www.djcxy.com/p/80316.html

    上一篇: 查找引用静态字符串的命令

    下一篇: andengine compileReleaseNdk错误