CMake错误在/path/to/android-ndk-r26c/build/cmake/android.toolchain.cmake:XX (message): 未知ABI: arm64-v8a-hard
CMake Error at /path/to/android-ndk-r26c/build/cmake/android.toolchain.cmake:XX (message): Unknown ABI: arm64-v8a-hard
ID: android/ndk-cmake-unknown-abi
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Android NDK r26c | active | — | — | — |
| Android NDK r25b | active | — | — | — |
| CMake 3.22.1 | active | — | — | — |
| Gradle 8.5 | active | — | — | — |
根因分析
NDK r26c移除了对'arm64-v8a-hard' ABI变体(具有硬件浮点优化)的支持,转而使用标准'arm64-v8a'。仍指定'-hard'后缀的项目在build.gradle或CMakeLists.txt中导致此错误。
English
NDK r26c removed support for the 'arm64-v8a-hard' ABI variant (which had hardware floating-point optimizations) in favor of standard 'arm64-v8a'. Projects still specifying '-hard' suffix in build.gradle or CMakeLists.txt cause this error.
官方文档
https://developer.android.com/ndk/guides/abis#arm64-v8a解决方案
-
Change build.gradle ndk.abiFilters to use 'arm64-v8a' instead of 'arm64-v8a-hard'. Example: defaultConfig { ndk { abiFilters 'arm64-v8a', 'x86_64' } } -
Update CMakeLists.txt to remove any -hard suffix from target_compile_options or set(CMAKE_ANDROID_ARM_MODE ARM) to ensure soft-float is used. Then clean rebuild.
无效尝试
常见但无效的做法:
-
Set ANDROID_ABI=arm64-v8a-hard in gradle.properties
95% 失败
NDK r26c no longer recognizes this ABI string. Setting it in properties just passes the same invalid value to CMake.
-
Downgrade NDK to r25b
60% 失败
This works temporarily but prevents using newer NDK features and security patches. Also breaks if other libraries require r26c.