CMake was unable to find a build program corresponding to “Ninja” solution

Error log:

> Configure project :app
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 24 for ABI ARMEABI_V7A and min SDK version 24
External native generate JSON debug: rebuilding JSON H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\debug\armeabi-v7a\android_gradle_build.json due to:
External native generate JSON debug: – command changed from previous, will remove stale json folder
External native generate JSON debug: removing stale contents from ‘H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\debug\armeabi-v7a’
External native generate JSON debug: created folder ‘H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\debug\armeabi-v7a’
External native generate JSON debug: executing cmake Executable : G:\Android_sdk_windows\cmake\3.10.2.4988404\bin\cmake.exe
arguments:
-HH:\git.code\dn\\
dk\\
dk_pusher\app
-BH:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\debug\armeabi-v7a
-DANDROID_ABI=armeabi-v7a
-DANDROID_PLATFORM=android-24
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=H:\git.code\dn\\
dk\\
dk_pusher\app\build\intermediates\cmake\debug\obj\armeabi-v7a
-DCMAKE_BUILD_TYPE=Debug
-DANDROID_NDK=G:\Android_sdk_windows\\
dk-bundle
-DCMAKE_CXX_FLAGS=
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a
-DCMAKE_SYSTEM_VERSION=24
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_ANDROID_NDK=G:\Android_sdk_windows\\
dk-bundle
-DCMAKE_TOOLCHAIN_FILE=G:\Android_sdk_windows\\
dk-bundle\build\cmake\android.toolchain.cmake
-G Ninja
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”: “H:/git.code/dn/ndk/ndk_pusher/app”,
“buildDirectory”: “H:/git.code/dn/ndk/ndk_pusher/app/.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\\=armeabi-v7a”,
“-DANDROID_PLATFORM\\=android-24”,
“-DCMAKE_LIBRARY_OUTPUT_DIRECTORY\\=H:\git.code\dn\\
dk\\
dk_pusher\app\build\intermediates\cmake \debug\obj\armeabi-v7a”,
“-DCMAKE_BUILD_TYPE\\=Debug”,
“-DANDROID_NDK\\=G:\Android_sdk_windows\\
dk-bundle”,
“-DCMAKE_CXX_FLAGS\\=”,
“-DCMAKE_SYSTEM_NAME\\=Android”,
“-DCMAKE_ANDROID_ARCH_ABI\\=armeabi-v7a”,
“-DCMAKE_SYSTEM_VERSION\\=24”,
“-DCMAKE_EXPORT_COMPILE_COMMANDS\\=ON”,
“-DCMAKE_ANDROID_NDK\\=G:\Android_sdk_windows\\
dk-bundle”,
“-DCMAKE_TOOLCHAIN_FILE\\=G:\Android_sdk_windows\\
dk-bundle\build\cmake\android.toolchain.cmake”,
“-G Ninja”
]
}

]== “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!\\
See also “H:/git .code/dn/ndk/ndk_pusher/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log”.”,”type”:”message”}

]== “CMake Server” ==]

Configuring incomplete, errors occurred!
See also “H:/git.code/dn/ndk/ndk_pusher/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log”.
Configuring incomplete, errors occurred!
See also “H:/git.code/dn/ndk/ndk_pusher/app/.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
External native generate JSON release: building json with force flag false
External native generate JSON release: starting JSON generation
External native generate JSON release: using platform version 24 for ABI ARMEABI_V7A and min SDK version 24
External native generate JSON release: rebuilding JSON H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\release\armeabi-v7a\android_gradle_build.json due to:
External native generate JSON release: – expected json H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\release\armeabi-v7a\android_gradle_build.json file is not present, will remove stale json folder
External native generate JSON release: – missing previous command file H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\release\armeabi-v7a\cmake_build_command.txt , will remove stale json folder
External native generate JSON release: removing stale contents from ‘H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\release\armeabi-v7a’
External native generate JSON release: created folder ‘H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\release\armeabi-v7a’
External native generate JSON release: executing cmake Executable : G:\Android_sdk_windows\cmake\3.10.2.4988404\bin\cmake.exe
arguments:
-HH:\git.code\dn\\
dk\\
dk_pusher\app
-BH:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\release\armeabi-v7a
-DANDROID_ABI=armeabi-v7a
-DANDROID_PLATFORM=android-24
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=H:\git.code\dn\\
dk\\
dk_pusher\app\build\intermediates\cmake\release\obj\armeabi-v7a
-DCMAKE_BUILD_TYPE=Release
-DANDROID_NDK=G:\Android_sdk_windows\\
dk-bundle
-DCMAKE_CXX_FLAGS=
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a
-DCMAKE_SYSTEM_VERSION=24
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_ANDROID_NDK=G:\Android_sdk_windows\\
dk-bundle
-DCMAKE_TOOLCHAIN_FILE=G:\Android_sdk_windows\\
dk-bundle\build\cmake\android.toolchain.cmake
-G Ninja
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”: “H:/git.code/dn/ndk/ndk_pusher/app”,
“buildDirectory”: “H:/git.code/dn/ndk/ndk_pusher/app/.externalNativeBuild/cmake/release/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\\=armeabi-v7a”,
“-DANDROID_PLATFORM\\=android-24”,
“-DCMAKE_LIBRARY_OUTPUT_DIRECTORY\\=H:\git.code\dn\\
dk\\
dk_pusher\app\build\intermediates\cmake \release\obj\armeabi-v7a”,
“-DCMAKE_BUILD_TYPE\\=Release”,
“-DANDROID_NDK\\=G:\Android_sdk_windows\\
dk-bundle”,
“-DCMAKE_CXX_FLAGS\\=”,
“-DCMAKE_SYSTEM_NAME\\=Android”,
“-DCMAKE_ANDROID_ARCH_ABI\\=armeabi-v7a”,
“-DCMAKE_SYSTEM_VERSION\\=24”,
“-DCMAKE_EXPORT_COMPILE_COMMANDS\\=ON”,
“-DCMAKE_ANDROID_NDK\\=G:\Android_sdk_windows\\
dk-bundle”,
“-DCMAKE_TOOLCHAIN_FILE\\=G:\Android_sdk_windows\\
dk-bundle\build\cmake\android.toolchain.cmake”,
“-G Ninja”
]
}

]== “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!\\
See also “H:/git .code/dn/ndk/ndk_pusher/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log”.”,”type”:”message”}

]== “CMake Server” ==]

Configuring incomplete, errors occurred!
See also “H:/git.code/dn/ndk/ndk_pusher/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log”.
Configuring incomplete, errors occurred!
See also “H:/git.code/dn/ndk/ndk_pusher/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log”.

[== “CMake Server” ==[

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

]== “CMake Server” ==]

Configuration failed.
External native generate JSON release: JSON generation completed with problems

CONFIGURE SUCCESSFUL in 46s
External native generate JSON debug: streaming 1 JSON files
External native generate JSON debug: streaming fallback JSON for H:\git.code\dn\\
dk\\
dk_pusher\app\.externalNativeBuild\cmake\debug\armeabi-v7a\android_gradle_build.json
External native generate JSON release: streaming 1 JSON files
External native generate JSON release: streaming fallback JSON for H:\git.code\dn\\
dk\\
dk_pusher\app\.external NativeBuild\cmake\release\armeabi-v7a\android_gradle_build.json
SIMPLE: Error configuring

The red part is the error message and log. We can see that the Ninja related environment cannot be found. CMAKE_MAKE_PROGRAM This is not set.

The solution is to modify the project gradle version. Not lower than 3.3.0

Wrong version:
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
}

After modification:

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
}

Summarize:

This problem usually occurs when upgrading android studio and related plug-ins. The problem occurred when I upgraded the NDK to 19.

The main issue is compatibility with old and new versions.