使用NDK构建Android项目时出错:通用ELF中的重定位(EM:40)

时间:2016-11-15 16:05:30

标签: android boost android-ndk

更新:我注意到控制台输出正在给我:

Error while executing 'C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\ndk-build.cmd' with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\bowli\Documents\Projects\AndroidStudioProjects\CDP_AR1\app\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\Users\bowli\Documents\Projects\AndroidStudioProjects\CDP_AR1\app\src\main\jni\Application.mk APP_ABI=mips NDK_ALL_ABIS=mips NDEBUG=1 APP_PLATFORM=android-14 NDK_OUT=C:/Users/bowli/Documents/Projects/AndroidStudioProjects/CDP_AR1/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\bowli\Documents\Projects\AndroidStudioProjects\CDP_AR1\app\build\intermediates\ndkBuild\debug\lib C:/Users/bowli/Documents/Projects/AndroidStudioProjects/CDP_AR1/app/build/intermediates/ndkBuild/debug/obj/local/mips/libcdpp_jni.so}

注意

  

APP_ABI = mips NDK_ALL_ABIS = mips

看来Android.mk和Application.mk中的值在某处被覆盖。现在我要试着找出它发生的地方。

基本问题:

我尝试使用提供的本机库构建一个Android应用程序:boost,MetaIO等。应用程序功能齐全,我只应该为它添加新功能。但是,当我尝试构建它时,我收到以下错误:

Error:process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

process_begin: CreateProcess(NULL, "", ...) failed.

C:/Users/bowli/Tools/Android/android-ndk/android-ndk-r8e/toolchains/mipsel-linux-android-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/mipsel-linux-android/4.6/../../../../mipsel-linux-android/bin/ld.exe: C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\sources/boost/android/lib/libboost_filesystem.a(path.o): Relocations in generic ELF (EM: 40)
C:/Users/bowli/Tools/Android/android-ndk/android-ndk-r8e/toolchains/mipsel-linux-android-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/mipsel-linux-android/4.6/../../../../mipsel-linux-android/bin/ld.exe: C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\sources/boost/android/lib/libboost_filesystem.a(path.o): Relocations in generic ELF (EM: 40)

*the same line over9000 times (around 40 actually)*

C:/Users/bowli/Tools/Android/android-ndk/android-ndk-r8e/toolchains/mipsel-linux-android-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/mipsel-linux-android/4.6/../../../../mipsel-linux-android/bin/ld.exe: C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\sources/boost/android/lib/libboost_filesystem.a(path.o): Relocations in generic ELF (EM: 40)
C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\sources/boost/android/lib/libboost_filesystem.a: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [C:/Users/bowli/Documents/Projects/AndroidStudioProjects/CDP_AR1/app/build/intermediates/ndkBuild/debug/obj/local/mips/libcdpp_jni.so] Error 1

我绝不是本地开发和配置它的专家,但是网上冲浪让我得出的结论是,没有针对我正在尝试编译的相同架构编译boost。因此,我尝试了所有更改Application.mk中的ABI以找出增强目标架构。我尝试了支持的ABI列表(https://developer.android.com/ndk/guides/abis.html)中的所有ABI,并且都产生了同样的错误。

然后我尝试为专为armv7(https://github.com/emileb/Boost-for-Android-Prebuilt)编译的那个更改给定的boost库,但是这给了我基本相同的错误:

C:/Users/bowli/Tools/Android/android-ndk/android-ndk-r8e/toolchains/mipsel-linux-android-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/mipsel-linux-android/4.6/../../../../mipsel-linux-android/bin/ld.exe: C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\sources/boost/armeabi-v7a/lib/libboost_filesystem-gcc-mt-1_53.a(path.o): Relocations in generic ELF (EM: 40)
C:\Users\bowli\Tools\Android\android-ndk\android-ndk-r8e\sources/boost/armeabi-v7a/lib/libboost_filesystem-gcc-mt-1_53.a: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [C:/Users/bowli/Documents/Projects/AndroidStudioProjects/CDP_AR1/app/build/intermediates/ndkBuild/debug/obj/local/mips/libcdpp_jni.so] Error 1

我的Application.mk:

APP_ABI      := armeabi-v7a
APP_STL      := gnustl_static
APP_CPPFLAGS := -fexceptions
APP_CPPFLAGS += -fpermissive
APP_CPPFLAGS += -frtti

我还必须指明:

TARGET_ARCH_ABI := armeabi-v7a

在我的Android.mk中,否则它出于某种原因想要为mips构建。

1 个答案:

答案 0 :(得分:2)

好吧,我明白了。

模块 Gradle构建文件以某种方式将ABI规范覆盖为mips。

我最终将以下内容添加到build.gradle中以解决问题:

android {
...

    defaultConfig {
        ...

        ndk {
            // Specifies the ABI configurations of your native
            // libraries Gradle should build and package with your APK.
            abiFilters 'armeabi-v7a'
        }
    }
    ...
}

更多信息:https://developer.android.com/studio/projects/add-native-code.html#link-gradle