7

I have the following CMAKE & Ninja installed through Android Studio's SDK Tools:

~/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja --version
1.8.2

I run into "Error Configuring" while trying to build my project. Here is the build output:

Executable : /Users/ssk/Library/Android/sdk/cmake/3.10.2.4988404/bin/cmake
arguments : 
-H/Users/ssk/MyProject
-B/Users/ssk/MyProject/.externalNativeBuild/cmake/debug/armeabi-v7a
-DANDROID_ABI=armeabi-v7a
-DANDROID_PLATFORM=android-16
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/ssk/MyProject/build/intermediates/cmake/debug/obj/armeabi-v7a
-DCMAKE_BUILD_TYPE=Debug
-DANDROID_NDK=/Users/ssk/Library/Android/sdk/ndk-bundle
-DCMAKE_CXX_FLAGS=-std=c++11
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a
-DCMAKE_SYSTEM_VERSION=16
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_ANDROID_NDK=/Users/ssk/Library/Android/sdk/ndk-bundle
-DCMAKE_TOOLCHAIN_FILE=/Users/ssk/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake
-G Ninja
-DANDROID_STL=gnustl_statics
-DANDROID_CPP_FEATURES=rtti exception
-DANDROID_TOOLCHAIN=gcc
-DANDROID_NDK=/Users/ssk/android-ndk-r17c/
jvmArgs : 

It's missing:

-DCMAKE_MAKE_PROGRAM=/Users/ssk/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja

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

Only if I switch to CMake version say 3.6.3155560 it works. Otherwise, I have to install ninja from brew or macports.

Here is the snippet from my build.gradle:

 externalNativeBuild {
        cmake {
            // Linker flags and Visibility options keeps the size of the library small
            cppFlags "-std=c++11"
            arguments "-DANDROID_STL=gnustl_static",
                      "-DANDROID_CPP_FEATURES=rtti exceptions",
                      "-DANDROID_TOOLCHAIN=gcc"
        }
    }

How to fix it?

shizhen
  • 12,251
  • 9
  • 52
  • 88
ssk
  • 9,045
  • 26
  • 96
  • 169
  • I was able to resolve this error message as described here: https://stackoverflow.com/questions/54666491/ndk-build-error-for-ninja-cmake-make-program-is-not-set/55676618 – Aur Saraf Apr 14 '19 at 14:56

1 Answers1

8

Install/Update CMake From Android Studio SDK Manager

Install/Update CMake From Android Studio SDK Manager

Check your CMake from sdk root directory if ninja exists. enter image description here


Below is not good.

cmake {
    cppFlags "-std=c++11"
    arguments "-DANDROID_ABI=armeabi-v7a",
                "-DANDROID_PLATFORM=android-16",
                "-DANDROID_STL=gnustl_static",
                "-DANDROID_CPP_FEATURES=rtti exceptions",
                "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=libs"
}

Because, ANDROID_PLATFORM should be automatically decided by Android external native build system according to minSdkVersion, see below official document from how ANDROID_PLATFORM works:

Instead of changing this flag directly, you should set the minSdkVersion property in the defaultConfig or productFlavors blocks of your module-level build.gradle file. This makes sure your library is used only by apps installed on devices running an adequate version of Android. The CMake toolchain then chooses the best platform version for the ABI you're building using the following logic:

  1. If there exists a platform version for the ABI equal to minSdkVersion, CMake uses that version. Otherwise,
  2. if there exists platform versions lower than minSdkVersion for the ABI, CMake uses the highest of those platform versions. This is a reasonable choice because a missing platform version typically means that there were no changes to the native platform APIs since the previous available version.
  3. Otherwise, CMake uses the next available platform version higher than minSdkVersion.

And, -DANDROID_ABI=armeabi-v7a is not good as well. You should not define this parameter here. CMake will iterate all your ABIs according to your abiFilters automatically. If you just want to build armeabi-v7a, you can specify this using abiFilter, e.g.

externalNativeBuild {
    cmake {
        abiFilters 'armeabi-v7a', 'arm64-v8a'
    }
}

Also, rtti and exceptions are cppFlags, below should be the proper way to set these two flags.

cppFlags "-std=c++11 -frtti -fexceptions"

Ensure that your have properly configured ANDROID_NDK path, because according to your question, you have TWO version of NDK set, one is -DANDROID_NDK=/Users/ssk/android-ndk-r17c/, the other one is -DANDROID_NDK=/Users/ssk/Library/Android/sdk/ndk-bundle. Config NDK path from local.properties:

ndk.dir=/Users/ssk/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/ssk/Library/Android/sdk

what is the fix for -GAndroid Gradle - Ninja?

Add below arguments to the cmake config:

externalNativeBuild { 
    cmake { 
        ...
        version "3.10.2"
        arguments "-GAndroid Gradle - Ninja"
    } 
} 
shizhen
  • 12,251
  • 9
  • 52
  • 88
  • Yes, it does exist and it’s @1.8.2 – ssk Feb 01 '19 at 05:26
  • 1
    Should be `-GAndroid Gradle - Ninja` rather than `-G Ninja`? How is your `gradle.build` like? See [Build arguments](https://developer.android.com/ndk/guides/cmake#options) – shizhen Feb 01 '19 at 05:38
  • 1
    Good catch, updated the question with the build.gradle. What is the fix? Thanks. – ssk Feb 01 '19 at 05:43
  • what is the fix for -GAndroid Gradle - Ninja? I am using gradle plugin 4.4. According to the documentation: -DCMAKE_MAKE_PROGRAM Tool to launch the native build system. The Gradle plugin sets this value to the CMake ninja generator bundled with the Android SDK. – ssk Feb 01 '19 at 05:55
  • Please update your `build.gradle` according to my comments and recompile to see the latest errors if any. – shizhen Feb 01 '19 at 05:58
  • Updated to: externalNativeBuild { cmake { cppFlags "-std=c++11 -frtti -fexceptions" arguments "-DANDROID_STL=gnustl_static", "-DANDROID_TOOLCHAIN=gcc" } } and I still see the problem. – ssk Feb 01 '19 at 06:02
  • remove `"-DANDROID_TOOLCHAIN=gcc" ` You have TWO ndk paths, `-DANDROID_NDK=/Users/ssk/android-ndk-r17c/` and the `ndk-bundle` one, clean this also.Latest Android is using `clang`, not `gcc` any more. – shizhen Feb 01 '19 at 06:04
  • @shizhen I have ninja in the cmake folder and I can run `ninja --version` in terminal. But still get: `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.`;;;; There is no `ndk.dir` in `local.properties` as AS uses ndk-bundle. – Dr.jacky Nov 04 '21 at 09:27