前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >"CMake Error: CMake was unable to find a build program corresponding Ninja"

"CMake Error: CMake was unable to find a build program corresponding Ninja"

原创
作者头像
望天
发布2019-09-26 13:51:18
2.6K0
发布2019-09-26 13:51:18
举报
文章被收录于专栏:along的开发之旅

前两天, 没修改什么, 打开Android Studio编so, 忽然就不成功了.

报错信息如下:

代码语言:txt
复制
Support for CMake 3.7 and higher is a preview feature. To report a bug, see https://developer.android.com/studio/report-bugs.html

Support for CMake 3.7 and higher is a preview feature. To report a bug, see https://developer.android.com/studio/report-bugs.html

External native generate JSON debug: building json with force flag false

External native generate JSON debug: starting JSON generation

External native generate JSON debug: using platform version 16 for ABI ARMEABI\_V7A and min SDK version 14

External native generate JSON debug: rebuilding JSON /Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a/android\_gradle\_build.json due to:

External native generate JSON debug: - expected json /Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a/android\_gradle\_build.json file is not present, will remove stale json folde

External native generate JSON debug: - missing previous command file /Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a/cmake\_build\_command.txt, will remove stale json folde

External native generate JSON debug: removing stale contents from '/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a'

External native generate JSON debug: created folder '/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a'

External native generate JSON debug: executing cmake Executable : /Users/along/Library/Android/sdk/cmake/3.10.2.4988404/bin/cmake

arguments : 

-H/Users/oncealong/Android-Project/

-B/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a

-DANDROID\_ABI=armeabi-v7a

-DANDROID\_PLATFORM=android-16

-DCMAKE\_LIBRARY\_OUTPUT\_DIRECTORY=/Users/oncealong/Android-Project/build/intermediates/cmake/debug/obj/armeabi-v7a

-DCMAKE\_BUILD\_TYPE=Debug

-DANDROID\_NDK=/Users/along/Library/Android/android-ndk-r18b

-DCMAKE\_CXX\_FLAGS=-frtti -fexceptions -D\_\_cdecl= -D\_\_stdcall=

-DCMAKE\_SYSTEM\_NAME=Android

-DCMAKE\_ANDROID\_ARCH\_ABI=armeabi-v7a

-DCMAKE\_SYSTEM\_VERSION=16

-DCMAKE\_EXPORT\_COMPILE\_COMMANDS=ON

-DCMAKE\_ANDROID\_NDK=/Users/along/Library/Android/android-ndk-r18b

-DCMAKE\_TOOLCHAIN\_FILE=/Users/along/Library/Android/android-ndk-r18b/build/cmake/android.toolchain.cmake

-G Ninja

-DANDROID\_TOOLCHAIN=clang

-DANDROID\_STL=c++\_static

jvmArgs : 





[== "CMake Server" ==[



{"supportedProtocolVersions":[{"isExperimental":true,"major":1,"minor":1}],"type":"hello"}



]== "CMake Server" ==]



[== "CMake Server" ==[



{

  "type": "handshake",

  "cookie": "gradle-cmake-cookie",

  "protocolVersion": {

    "isExperimental": true,

    "major": 1,

    "minor": 1

  },

  "sourceDirectory": "/Users/oncealong/Android-Project/",

  "buildDirectory": "/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a",

  "generator": "Ninja"

}



]== "CMake Server" ==]



[== "CMake Server" ==[



{"cookie":"gradle-cmake-cookie","inReplyTo":"handshake","type":"reply"}



]== "CMake Server" ==]



[== "CMake Server" ==[



{

  "type": "configure",

  "cacheArguments": [

    "",

    "-DANDROID\_ABI\u003darmeabi-v7a",

    "-DANDROID\_PLATFORM\u003dandroid-16",

    "-DCMAKE\_LIBRARY\_OUTPUT\_DIRECTORY\u003d/Users/oncealong/Android-Project/build/intermediates/cmake/debug/obj/armeabi-v7a",

    "-DCMAKE\_BUILD\_TYPE\u003dDebug",

    "-DANDROID\_NDK\u003d/Users/along/Library/Android/android-ndk-r18b",

    "-DCMAKE\_CXX\_FLAGS\u003d-frtti -fexceptions -D\_\_cdecl\u003d -D\_\_stdcall\u003d",

    "-DCMAKE\_SYSTEM\_NAME\u003dAndroid",

    "-DCMAKE\_ANDROID\_ARCH\_ABI\u003darmeabi-v7a",

    "-DCMAKE\_SYSTEM\_VERSION\u003d16",

    "-DCMAKE\_EXPORT\_COMPILE\_COMMANDS\u003dON",

    "-DCMAKE\_ANDROID\_NDK\u003d/Users/along/Library/Android/android-ndk-r18b",

    "-DCMAKE\_TOOLCHAIN\_FILE\u003d/Users/along/Library/Android/android-ndk-r18b/build/cmake/android.toolchain.cmake",

    "-G Ninja",

    "-DANDROID\_TOOLCHAIN\u003dclang",

    "-DANDROID\_STL\u003dc++\_static"

  ]

}



]== "CMake Server" ==]



[== "CMake Server" ==[



{"cookie":"","inReplyTo":"configure","message":"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.","title":"Error","type":"message"}



]== "CMake Server" ==]



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.





[== "CMake Server" ==[



{"cookie":"","inReplyTo":"configure","progressCurrent":1000,"progressMaximum":1000,"progressMessage":"Configuring","progressMinimum":0,"type":"progress"}



]== "CMake Server" ==]



[== "CMake Server" ==[



{"cookie":"","inReplyTo":"configure","message":"Configuring incomplete, errors occurred!\nSee also \"/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log\".","type":"message"}



]== "CMake Server" ==]



Configuring incomplete, errors occurred!

See also "/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".

Configuring incomplete, errors occurred!

See also "/Users/oncealong/Android-Project/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".





[== "CMake Server" ==[



{"cookie":"","errorMessage":"Configuration failed.","inReplyTo":"configure","type":"error"}



]== "CMake Server" ==]



Configuration failed.

External native generate JSON debug: JSON generation completed with problems



FAILURE: Build failed with an exception.



\* What went wrong:

A problem occurred configuring project ':armplayer-lib'.

> executing external native build for cmake /Users/oncealong/Android-Project/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.

找了下资料, 只有如何修复这个问题, 没有为什么这么修复. 最终找到了官网:

https://developer.android.com/studio/projects/add-native-code#vanilla\_cmake

官网表示现在支持CMake 3.6和3.10, 但是gradle默认选择3.6.

如果配置成3.10, 我按照官网的3.10配置没成功, 按照官网的"Use a custom CMake version"配置成功.

这里应该是gradle plugin低版本和CMake 3.10默认设置不匹配导致, 需要额外手动介入解决.

推荐的是直接按照官网的"Use a custom CMake version"来解决.

Use CMake 3.6.0 or 3.10.2

The SDK Manager includes the 3.6.0 forked version of CMake and version 3.10.2. Projects that don't set a specific CMake version in build.gradle are built with CMake 3.6.0. To use the later included version, specify CMake version 3.10.2 in your module's build.gradle file:

代码语言:txt
复制
android {

    ...

    externalNativeBuild {

        cmake {

            ...

            version "3.10.2"

        }

    }

}

While not a best practice, you may specify the CMake version as the minimum version by adding a + to the end of the build.gradle entry, such as 3.10+ or 3+.

Use a custom CMake version

If you want to use a CMake version 3.7 or higher that is not included by the SDK Manager, follow these steps:

  1. Download and install CMake 3.7 or higher from the official CMake website.
  2. Specify the CMake version you want Gradle to use in your module's build.gradle file: android { ... externalNativeBuild { cmake { ... version "cmake-version" } } }
  3. Either add the path to the CMake installation to your PATH environment variable or include it in your project's local.properties file, as shown below. If Gradle is unable to find the version of CMake you specified in your build.gradle file, you get a build error. # If you set this property, Gradle no longer uses PATH to find CMake. cmake.dir="path-to-cmake"
  4. If you don't already have the Ninja build system installed on your workstation, go to the official Ninja website, and download and install the latest version of Ninja available for your OS. Make sure to also add the path to the Ninja installation to your PATH environment variable.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Use CMake 3.6.0 or 3.10.2
  • Use a custom CMake version
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档