CMake Android配置失败

时间:2018-11-22 11:44:24

标签: android c++ cmake

我正在尝试为Android编译动态库。我在Windows上使用CMake-gui来做到这一点。几年前,我成功地构建了库(TagLib)。但是现在工具链不再起作用了。

如果我尝试将 android.toolchain.cmake 脚本指向NDK R18,它将失败并显示以下错误消息:

Android: Targeting API '22' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
CMake Error at C:/app/cmake/share/cmake-3.12/Modules/Platform/Android/Determine-Compiler-NDK.cmake:97 (message):
  Android: No toolchain for ABI 'armeabi-v7a' found in the NDK:

我认为这可能与Android NDK现在从GCC切换到Clang的事实有关。因此,我尝试了较旧的NDK R16b。现在,它又进一步了,但是现在仍然失败,并显示以下错误消息:

CMake Error at C:/app/cmake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):   The C compiler

    "c:/app/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Moje/QtProjects/taglib_build/CMakeFiles/CMakeTmp

    Run Build Command:"C:/Qt/Tools/mingw530_32/bin/mingw32-make.exe" "cmTC_9e009/fast"
    C:/Qt/Tools/mingw530_32/bin/mingw32-make.exe -f CMakeFiles\cmTC_9e009.dir\build.make CMakeFiles/cmTC_9e009.dir/build

    mingw32-make.exe[1]: Entering directory 'C:/Moje/QtProjects/taglib_build/CMakeFiles/CMakeTmp'

    Building C object CMakeFiles/cmTC_9e009.dir/testCCompiler.c.o

    c:\app\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-gcc.exe
-target armv7-none-linux-androideabi --sysroot=C:/app/android-ndk-r16b/platforms/android-22/arch-arm  -isystem C:\app\android-ndk-r16b\platforms\android-22\arch-arm\usr\include
-isystem C:\app\android-ndk-r16b\platforms\android-22\arch-arm\usr\include\arm-linux-androideabi
-g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -fPIE   -o CMakeFiles\cmTC_9e009.dir\testCCompiler.c.o   -c C:\Moje\QtProjects\taglib_build\CMakeFiles\CMakeTmp\testCCompiler.c

    arm-linux-androideabi-gcc.exe: error: armv7-none-linux-androideabi: No such file or directory

    arm-linux-androideabi-gcc.exe: error: unrecognized command line option '-target'

    arm-linux-androideabi-gcc.exe: error: unrecognized command line option '-fno-integrated-as'

    arm-linux-androideabi-gcc.exe: error: unrecognized command line option '-fno-limit-debug-info'

    CMakeFiles\cmTC_9e009.dir\build.make:64: recipe for target 'CMakeFiles/cmTC_9e009.dir/testCCompiler.c.o' failed

    mingw32-make.exe[1]: *** [CMakeFiles/cmTC_9e009.dir/testCCompiler.c.o] Error 1

    mingw32-make.exe[1]: Leaving directory 'C:/Moje/QtProjects/taglib_build/CMakeFiles/CMakeTmp'

    Makefile:120: recipe for target 'cmTC_9e009/fast' failed

    mingw32-make.exe: *** [cmTC_9e009/fast] Error 2

我不了解测试命令出了什么问题以及为什么它失败了。你有什么主意吗?

毕竟,我构建动态Android库的方法正确还是有更好的方法呢?我不使用Android Studio,而是在QtCreator中开发应用程序。

1 个答案:

答案 0 :(得分:0)

当我尝试使用控制台命令在macOS上构建Android .apk时,我的问题几乎相同。 Visual Studio GUI可以正常生成,而 msbuild 会出错:

error XA5101: C compiler for target Arm was not found. 

Xamarin forum here上进行了讨论。

在这里找到的解决方法对我有用,是在 Android.csproj 中关闭 BundleAssemblies 参数:

<BundleAssemblies>False</BundleAssemblies>

here也建立了我的NDK和工具链路径错误的解决方案。我安装了最新版本的Android SDK和NDK。