Unable to find CMake in Android Studio

AndroidAndroid StudioAndroid NdkCmake

Android Problem Overview


I need to add C/C++ code in my Android program for which I needed LLDB, CMake, and NDK. I found LLDB and NDK in SDK manager, but CMake is missing from there. I tried manually downloading it from the CMake official site and found out that for Android we need SDK customized CMake.

Enter image description here

As you can see there is no option such as CMake.

Where do I find a version of CMake for Android?

I have tried CMake from the website and one I found in ndk-bundle/build folder, but both are giving the same error as below. What can be made out of it and how can the issue be solved?

Build command failed.

Error while executing 'C:\Users\amishr33\AppData\Local\Android\sdk\cmake\bin\cmake.exe' with arguments {-HC:\Users\amishr33\AndroidStudioProjects\MyApplication\app\src\main\jni -BC:\Users\amishr33\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=C:\Users\amishr33\AppData\Local\Android\sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\amishr33\AndroidStudioProjects\MyApplication\app\build\intermediates\cmake\debug\obj\armeabi -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Users\amishr33\AppData\Local\Android\sdk\cmake\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\amishr33\AppData\Local\Android\sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=15 -DCMAKE_CXX_FLAGS=-std=c++11 -DANDROID_TOOLCHAIN=clang -DANDROID_STL=gnustl_static}
CMake Error: Could not create named generator Android Gradle - Ninja
Generators
  Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
                                 Optional [arch] can be "Win64" or "IA64".
  Visual Studio 9 2008 [arch]  = Generates Visual Studio 2008 project files.
                                 Optional [arch] can be "Win64" or "IA64".
  Visual Studio 8 2005 [arch]  = Generates Visual Studio 2005 project files.
                                 Optional [arch] can be "Win64".
  Visual Studio 7 .NET 2003    = Deprecated.  Generates Visual Studio .NET
                                 2003 project files.
  Borland Makefiles            = Generates Borland makefiles.
  NMake Makefiles              = Generates NMake makefiles.
  NMake Makefiles JOM          = Generates JOM makefiles.
  Green Hills MULTI            = Generates Green Hills MULTI files
                                 (experimental, work-in-progress).
  MSYS Makefiles               = Generates MSYS makefiles.
  MinGW Makefiles              = Generates a make file for use with
                                 mingw32-make.
  Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
  CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - MinGW Makefiles   = Generates CodeLite project files.
  CodeLite - NMake Makefiles   = Generates CodeLite project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Sublime Text 2 - MinGW Makefiles
                               = Generates Sublime Text 2 project files.
  Sublime Text 2 - NMake Makefiles
                               = Generates Sublime Text 2 project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.
  Kate - MinGW Makefiles       = Generates Kate project files.
  Kate - NMake Makefiles       = Generates Kate project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Eclipse CDT4 - NMake Makefiles
                               = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - MinGW Makefiles
                               = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Error:executing external native build for cmake C:\Users\amishr33\AndroidStudioProjects\MyApplication\app\src\main\jni\CMakeLists.txt

Android Solutions


Solution 1 - Android

  • Open SDK Manager
  • Switch to the SDK Tools tab
  • Install CMake

Example Image

Solution 2 - Android

If you do the following you may get CMake without any problems:

  1. Open the Settings (Android Studio);
  2. Search by "Android SDK";
  3. On the right side, go to the "SDK Tools" pallet|tab;
  4. Check the "CMake" item on the list;
  5. Press OK button;
  6. Now, just wait the next century while Gradle builds, =D .

Solution 3 - Android

  1. Check in your build.gradle file for your App's module

     externalNativeBuild {
         cmake {
             path "CMakeLists.txt"
         }
     }
    
  2. Remove the cmake section

  3. Re-synchronise the project: go to menu Build -> Refersh Lined C++ Projects

  4. Right-click on the module, such as the app module, select "Link C++ Project with Gradle" from the menu.

  5. You should see a dialog similar to the one shown in below figure.

    Enter image description here

  6. Click OK.

Solution 4 - Android

  • Go to Android SDK manager
  • Select Android SDK Tools
  • Find CMake and click Apply to download.
  • Later click OK Instructions

Solution 5 - Android

Actually, I'm not sure if my solution will be relevant, I will leave it here anyways

go to /Users/yournamehere/Library/Android/sdk/ndk I found the version 21.4.7075529 and deleted it, and then downloaded the same version again using android studio from configuration > Preferences and follow the steps in the attached imageenter image description here

Solution 6 - Android

place path of the module where your cmake is exist

if your cmake exist in app main

 externalNativeBuild {
                cmake {
                        path "CMakeLists.txt"
                      }
            }
 

 

if your cmake exist in any module

  externalNativeBuild {
                cmake {
                    path file('../modulelib/CMakeLists.txt')
                }
            }

where "modulelib" is your library module folder name

Solution 7 - Android

In my case changing CMake path worked :

externalNativeBuild {
    /*
      cmake {
          path "CMakeLists.txt"
      }
    */

    cmake {
        path 'src/main/jni/opus/CMakeLists.txt'
    }
}

Solution 8 - Android

In my case (Android Studio 3.0), there was no CMake in the "SDK Tools" tab in "Appearance & Behaviour -> System Settings -> Android SDK" options. However I noticed that in the "SDK Update sites" tab, there are only two entries, one of which (Android Repository https://dl.google.com/android/repository/repository2-1.xml) had a red mark in the "enabled" column. It read "error 407" on mouseover, which is a proxy authentication error. I had the correct proxy settings (test connection worked fine with the same repository URL), so this was very strange. Restarting android studio didn't help. So I added a new entry with the same repository and this time it worked fine and CMake appeared in the other tab. Hope this helps someone.

Solution 9 - Android

You can install it in the SDK Manager Tools, but first you must close your opened project. Use configuration on start menu.

Solution 10 - Android

enter image description here

  1. Open Android Studio 
  2. Hover over your toolbar until you find SDK Manager, as in the image above
  3. Click on SDK Manager
  4. In Default Preferences, go to Appearance and Behavior
  5. Now select System Settings
  6. Now select Android SDK
  7. Click on SDK Tools
  8. Check on CMake

Solution 11 - Android

Check if you are using a 64-bit version of Android Studio. In Android Studio 32 bit, CMake will not appear in SDK Manager.

Solution 12 - Android

For me what solved as taking off the "version" option in my gradle

 externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            //version was here
        }
    }

Solution 13 - Android

Check this, I think this site explains what you need:

https://codelabs.developers.google.com/codelabs/android-studio-cmake/index.html?index=..%2F..%2Findex#0

Remember to check the "What you'll need"

#Update:#

NDK: https://developer.android.com/ndk/downloads/index.html source: https://developer.android.com/ndk/index.html

CMake: https://cmake.org/files/v3.7/cmake-3.7.1-win64-x64.zip source: https://cmake.org/

LLDB (Just for Debian systems): http://apt.llvm.org/ source: http://lldb.llvm.org/download.html

Once you download these files, copy to your SDK folder (normally in: "C:\android-sdk") You can localize the folder here:

  1. File -> project Structure into Project Structure
  2. Left -> SDK Location

Then you can continue with the previous guide after the downloads :)

Solution 14 - Android

For me, mac OS Android studio. in File->Project Structure-> Project, I changed Gradle version to 4.4 and Android plugin version to 3.1.0, then it gets good.

Plus, you can also change Android plugin version in gradle-> classpath 'com.android.tools.build:gradle:3.1.0'

Solution 15 - Android

I'm on Android Studio 4.2 C15 using SDK 30 in tandem with OpenCV 4 and Ninja, and in my case changing the CMake path like below worked:

externalNativeBuild {
    /*
      cmake {
          path "CMakeLists.txt"
      }
    */

    cmake {
         path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
    }
}

Solution 16 - Android

For me the error was:

> CMake '3.10.2' was not found in SDK, PATH, or by cmake.dir property

I solved it by adding + to CMake version.

externalNativeBuild {
    cmake {
        path file('src/main/cpp/CMakeLists.txt')
        version '3.10.2+' // added plus after version
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionashish mishraView Question on Stackoverflow
Solution 1 - AndroidKemal TürkView Answer on Stackoverflow
Solution 2 - AndroidFabio FilhoView Answer on Stackoverflow
Solution 3 - Androiduser2477865View Answer on Stackoverflow
Solution 4 - AndroidGirish B.RView Answer on Stackoverflow
Solution 5 - AndroidEslam AdelView Answer on Stackoverflow
Solution 6 - AndroidAMDView Answer on Stackoverflow
Solution 7 - AndroidNilesh DeokarView Answer on Stackoverflow
Solution 8 - AndroidThe White LionView Answer on Stackoverflow
Solution 9 - AndroidJeremy ClarksonView Answer on Stackoverflow
Solution 10 - AndroidYusufView Answer on Stackoverflow
Solution 11 - AndroidSnowbasesView Answer on Stackoverflow
Solution 12 - AndroidPPPView Answer on Stackoverflow
Solution 13 - AndroidAlbertoView Answer on Stackoverflow
Solution 14 - Androidran5515View Answer on Stackoverflow
Solution 15 - AndroidMiguel TomásView Answer on Stackoverflow
Solution 16 - AndroidYunis RasulzadeView Answer on Stackoverflow