andengine compileReleaseNdk错误 [英] andengine compileReleaseNdk error

查看:73
本文介绍了andengine compileReleaseNdk错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的android studio项目中使用andengine,但是在构建时出现ndk错误.

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

我想我缺少一些OpenGL文件吗?

I suppose I'm missing some OpenGL files?

推荐答案

Android Gradle插件的NDK任务实际上并未使用jni/文件夹中可能提供的任何Android.mk文件.在我弄清楚这一点之前,这对我来说是一个很大的困惑.

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.

它会根据您在Gradle构建脚本中设置的参数以及jni/文件夹的内容,在构建过程中生成一个中间的Android.mk文件.

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.

您可以通过在请注意第126行的writeMakeFile(...)方法.

Note the writeMakeFile(...) method on line 126.

这就是为什么您从作为Gradle构建的一部分运行的ndk-build命令中得到的错误引用了构建脚本APP_BUILD_SCRIPT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\build\intermediates\ndk\release\Android.mk,而不是您可能希望并希望的APP_BUILD_SCRIPT=D:\Android\workspace\simpleclock\simple_clock_as\andEngine\src\main\jni\Android.mk之类的东西.

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.

无法让Android Gradle插件的NDK任务使用您自己的Android.mk文件(请相信我,如果我能找到它的话!).

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!).

您可以通过以下两种方法将NDK代码作为Gradle的一部分进行编译:

You have two options for getting your NDK code compiling as part of Gradle:

  1. 找出正确的配置以放入build.gradle中,以便生成的Android.mk文件包含所需的LOCAL_LDLIBS := -lGLESv2行以及
  1. 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.
  2. 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.

我认为在这种情况下,选项1是打开的,因此当然是更可取的解决方案.

I think in this case option 1 is open and so of course the preferable solution.

像这样添加到android defaultConfig块中的东西应该可以工作:

Something like this added to the android defaultConfig block should work:

android {
    defaultConfig {
        ndk {
            moduleName "myNDKModule"
            stl "stlport_shared"
            ldLibs "lGLESv2"
            cFlags "-Werror"
        }
    }
}

不幸的是,我不是C语言/本机代码专家(我几乎一无所知),所以无法猜测AndEngine是否需要将LOCAL_MODULE_FILENAMELOCAL_EXPORT_C_INCLUDES设置为正确构建. 如果这样做,则需要采用方法2(至少直到/当Android Gradle NDK任务支持配置它们时).尽管我刚刚检查了AndEngine git存储库,并在将其从其Android.mk文件中删除后成功运行了ndk-build,这是有希望的.

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).

这篇关于andengine compileReleaseNdk错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆