Android的CMake配置失败



我正在尝试为Android编译一个动态库。我在Windows上使用CMakegui来做这件事。几年前我成功地构建了这个库(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:

我认为这可能与安卓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 CMakeFilescmTC_9e009.dirbuild.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:appandroid-ndk-r16btoolchainsarm-linux-androideabi-4.9prebuiltwindows-x86_64binarm-linux-androideabi-gcc.exe
-target armv7-none-linux-androideabi --sysroot=C:/app/android-ndk-r16b/platforms/android-22/arch-arm  -isystem C:appandroid-ndk-r16bplatformsandroid-22arch-armusrinclude
-isystem C:appandroid-ndk-r16bplatformsandroid-22arch-armusrincludearm-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 CMakeFilescmTC_9e009.dirtestCCompiler.c.o   -c C:MojeQtProjectstaglib_buildCMakeFilesCMakeTmptestCCompiler.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'
CMakeFilescmTC_9e009.dirbuild.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库的方法是正确的吗?或者有更好的方法吗?我不使用安卓工作室,我在QtCreator中开发我的应用程序。

当我试图用控制台命令在macOS上构建Android.apk时,我的问题几乎是一样的。Visual Studio GUI构建正常,msbuild则会出现错误:

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

这在Xamarin论坛上讨论过。

在这里找到并为我工作的方法是关闭Android中的BundleAssemblies参数。csproj:

<BundleAssemblies>False</BundleAssemblies>

此外,我的解决方案与错误的NDK和工具链路径是建立在这里。我安装了最新版本的Android SDK和NDK。

最新更新