andengine compileReleaseNdk 错误 [英] andengine compileReleaseNdk error

查看:22
本文介绍了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.

您可以在 https://android.googlesource.com/platform/tools/base/+/55aebda607efcc29b8d9d5e1a99d446e320ff288/build-system/gradle/src/main/groovy/com/android/build/gradle/tasks/NdkCompile.groovy.

注意第 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 行和 https://github.com/nicolasgramlich/AndEngine/blob/GLES2/jni/Android.mk 是必需的.
  2. 编写一个直接使用 AndEnginge 的 Android.mk 文件的自定义 NDK 编译任务.我最近不得不自己为 NDK 源集执行此操作,该源集需要的参数比 Android Gradle 插件当前支持通过 Gradle 传递的参数多,因此如果遇到此问题,我可以提供帮助.

我认为在这种情况下,选项 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/native 代码专家(我几乎什么都不知道)所以无法猜测 AndEngine 是否需要 LOCAL_MODULE_FILENAMELOCAL_EXPORT_C_INCLUDES 设置为正确构建.如果是这样,您将需要采用方法 2(至少在 Android Gradle NDK 任务支持配置它们之前).尽管我刚刚检查了 AndEngine git repo 并在将它们从其 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.

(我发现可以通过检查 https://android.googlesource.com/platform/tools/base/+/55aebda607efcc29b8d9d5e1a99d446e320ff288/build-system/src/main/groovy/com/android/build/gradle/internal/dsl/NdkConfigDsl.java).

(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天全站免登陆