[英]CMake configure for Android fails
我正在嘗試為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中開發應用程序。
當我嘗試使用控制台命令在macOS上構建Android .apk時,我的問題幾乎相同。 Visual Studio GUI可以正常生成,而msbuild會出錯:
error XA5101: C compiler for target Arm was not found.
在Xamarin論壇上進行了討論。
在這里找到的解決方法對我有用,是在Android.csproj中關閉BundleAssemblies參數:
<BundleAssemblies>False</BundleAssemblies>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.