当我构建一个包含ndk代码的android项目时。我收到以下错误:
Build command failed.
Error while executing process /home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app -B/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/.externalNativeBuild/cmake/debug/armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=/home/gongzelong/Android/Sdk/ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/build/intermediates/cmake/debug/obj/armeabi -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/home/gongzelong/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-14 -DCMAKE_CXX_FLAGS=}
/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Build command failed.
Error while executing process /home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app -B/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/.externalNativeBuild/cmake/release/armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=/home/gongzelong/Android/Sdk/ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/build/intermediates/cmake/release/obj/armeabi -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/home/gongzelong/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-14 -DCMAKE_CXX_FLAGS=}
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
我试图找到原因。
我发现了以下内容:
gongzelong@gongzelong:~/Android/Sdk/cmake/3.6.4111459/bin$ cmake -version
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/home/gongzelong/Android/Sdk/cmake/3.6.4111459/share/cmake-3.5
cmake version 3.5.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
似乎cmake分别有版本3.5和3.6。
有人能指出如何修复它并成功构建android项目吗?
更新
我删除了cmake并在android studio sdk manager中再次安装。
我仍然有这个:
null
Build command failed.
Error while executing process /home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app -B/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/.externalNativeBuild/cmake/debug/armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=/home/gongzelong/Android/Sdk/ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/build/intermediates/cmake/debug/obj/armeabi -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/home/gongzelong/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-14 -DCMAKE_CXX_FLAGS=}
/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Build command failed.
Error while executing process /home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app -B/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/.externalNativeBuild/cmake/release/armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=/home/gongzelong/Android/Sdk/ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/media/gongzelong/TOSHIBA/Code/Code/ImageLoaderEncapsulation/ImageLoader/ImageLoaderDemo/app/build/intermediates/cmake/release/obj/armeabi -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/home/gongzelong/Android/Sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/home/gongzelong/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-14 -DCMAKE_CXX_FLAGS=}
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
答案 0 :(得分:11)
您好像使用的NDK版本不再支持某些ABI(错误日志中的armeabi),因此您必须升级 build.gradle(Project:....)强>到最新的
classpath 'com.android.tools.build:gradle:3.1.3'
在 gradle-wraper.properties :distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
最后,您必须在 build.gradle(模块:应用)的android块中添加 abiFilters ,具体取决于您需要的ABI:
android {
....
defaultConfig {
externalNativeBuild {
cmake {
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
}
}
}
....
}
答案 1 :(得分:8)
就我而言,在build.gradle(Module:app)中进行以下更改对我有帮助。
原始
android {
....
defaultConfig {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=gnustl_static' ... [other args]
}
}
}
....
}
随着我的改变
android {
android.buildToolsVersion "28.0.3"
....
defaultConfig {
externalNativeBuild {
cmake {
'-DANDROID_STL=c++_static' ... [other args]
}
}
}
....
}
答案 2 :(得分:5)
我有同样的错误,我的ndk-bundle是最新的,它是ndk-r18b
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage Configuring incomplete, errors occurred!
我使用android-ndk-r14b进行了修复,您可以在local.properties
中指定它
ndk.dir=/Users/xxxx/Library/Android/sdk/android-ndk-r14b
当然,您应该先下载r14b,然后将其解压缩到sdk文件夹下