重新编译使用CMake的旧项目的问题处理
Posted 疯狂小芋头
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了重新编译使用CMake的旧项目的问题处理相关的知识,希望对你有一定的参考价值。
文章目录
使用最新版本 NDK(19版本)进行旧项目编译时,发现无法编译成功。原项目是使用 CMake 进行配置的,但是由于原项目编译环境被移除掉了,所以需要重新配置编译环境。
Error:CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Configuration failed.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> executing external native build for cmake /Users/taro/gitcode/android/XLink_Gateway_NDK/app/CMakeLists.txt
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
发生这个问题的原因是由于没有配置 cmake 的编译程序。该配置是通过 gradle 文件进行配置的。编译系统为 Mac OSX。
先说项目编译的前提。由于项目是通过 CMake 进行编译的,所以 CMake 是必须的。实际上原来的系统中已经安装了 CMake ,但是在 AS make project
时依然提示未安装 CMake,需要按以下方式进行排查。
- 首先通过 SDK Manager 确认是否已安装了 CMake,如果没有则需要安装
- 确认自己的系统中存在 cmake 程序和 ninja 程序
➜ bin git:(master) ✗ where cmake
/usr/local/bin/cmake
➜ bin git:(master) ✗ where ninja
/usr/local/bin/ninja
如果发现没有安装 ninja ,在 Mac OSX 中可以通过 homebrew 进行安装
//安装过程时间有点长,需要耐心等待,不需要翻墙
brew install ninja
如果 homebrew 安装时发现安装 ninja 失败(这边出现的情况时在下载文件时失败,该下载地址通过浏览器访问确实是无效的),建议确认一下是否需要进行 homebrew 的更新
brew update
如果无法访问 /usr/local/bin
文件夹,没有权限,这是由于 Mac OSX 系统后面的安装限制,请参考文章进行修改。mac 10.13 /usr/local 权限限制。
注意:即使开了权限 homebrew 也可能是 update 失败,此时可以尝试先执行
brew upgrade
再执行brew update
,有可能是版本太旧了
- 确认 gradle 中的 cmake 配置信息
android
defaultConfig
externalNativeBuild
cmake
arguments "-DANDROID_STL=c++_static",
//这里使用的地址就是上面查询到的 ninja 的地址
"-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja"
- 如果编译时提示 cmakeLists 文件的错误,请注意是否为
ANDROID_STL
配置错误的原因
原项目使用 -DANDROID_STL=gnustl_static
,但是高版本的 NDK 不支持,需要修改为 -DANDROID_STL=c++_static
。
- 如果编译时发现存在一些 ABI 系统架构不支持的情况,需要根据提示在 gradle 文件中屏蔽相应的 ABI
在原项目中默认编译的 ABI 包括
include 'x86','x86_64','armeabi-v7a','arm64-v8a','armeabi','mips','mips64'
但是实际上编译时提示后三个都不支持,此时屏蔽掉
include 'x86','x86_64','armeabi-v7a','arm64-v8a'//,'armeabi','mips','mips64'
备注:
- 原项目使用的 NDK 版本是 15,在使用旧版本原编译环境的 NDK 版本编译时,不需要修改配置文件,ABI 架构也是全部都是支持的。
所以能不随便去改 NDK 版本(或者说编译环境)千万不要去动,否则:编译环境一变化,同事两行泪
- 根据另一个同事反馈,其实也不用专门去安装
ninja
,在 AS 帮我们安装的 cmake 里已经有了 ninja 的程序,只需要把该地址补充即可(但是同事是使用旧版本的 NDK 编译,原项目并不需要添加编译程序的路径,但是重新配置编译环境时就变得需要了,不确定问题原因是什么。)
-DCMAKE_MAKE_PROGRAM=~/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja
以上是关于重新编译使用CMake的旧项目的问题处理的主要内容,如果未能解决你的问题,请参考以下文章