Android Studio CMake Error: Build Command failed

android studio ninja
error: cause: executing external native build for cmake
cmake android
simple: error configuring android studio
android cmake prebuilt library
android cmake find_library
external native build issues error configuring
android cmake include_directories

I'm running into an Error when I open a new project in Android Studio from the Code Samples (Hello JIN). When the Project is opened the following:

Build command failed.
Error while executing process /opt/android-sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/src/main/cpp -B/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a -GAndroid Gradle - Ninja -DANDROID_ABI=arm64-v8a -DANDROID_NDK=/opt/android-sdk/ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/build/intermediates/cmake/arm8/release/obj/arm64-v8a -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/opt/android-sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-23 -DANDROID_TOOLCHAIN=clang}
-- Check for working C compiler: /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- broken
-- Configuring incomplete, errors occurred!
See also "/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeOutput.log".
See also "/home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeError.log".
CMake Error at /opt/android-sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler
  "/opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
  is not able to compile a simple test program.
  It fails with the following output:
   Change Dir: /home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeTmp
  Run Build Command:"/opt/android-sdk/cmake/3.6.4111459/bin/ninja"
  "cmTC_0053d"
  [1/2] Building C object CMakeFiles/cmTC_0053d.dir/testCCompiler.c.o
  FAILED:
  /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  --target=aarch64-none-linux-android
  --gcc-toolchain=/opt/android-sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
  --sysroot=/opt/android-sdk/ndk-bundle/sysroot -isystem
  /opt/android-sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android
  -D__ANDROID_API__=23 -g -DANDROID -ffunction-sections -funwind-tables
  -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat
  -Werror=format-security -fPIE -o
  CMakeFiles/cmTC_0053d.dir/testCCompiler.c.o -c
  /home/max/Documents/AndroidStudioProjects/HelloJNI1/app/.externalNativeBuild/cmake/arm8Release/arm64-v8a/CMakeFiles/CMakeTmp/testCCompiler.c
  /opt/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang:
  error while loading shared libraries: libncurses.so.5: cannot open shared
  object file: No such file or directory
  ninja: build stopped: subcommand failed.
  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt

This Error drops mutliple times in the IDE

I'm using Arch-Linux 64x

Cmake.txt:

    cmake_minimum_required(VERSION 3.4.1)

add_library(hello-jni SHARED
            hello-jni.c)

# Include libraries needed for hello-jni lib
target_link_libraries(hello-jni
                      android
                      log)

Build -> Refresh Linked C++ Projects resolved this error for me.

Build command failed. · Issue #510 · android/ndk-samples · GitHub, Error info. Build command failed. Error while executing process C:\Users\​Administrator\AppData\Local\Android\Sdk\cmake\3.6.4111459  I have tried several days installing the NDK into Android Studio but it always gives me an error message saying that the build failed and I should install a c compiler.

@rpurohit was nearly right, Clang isn't working properly. But to change the Compiler you need to change build.gradle, in my build.gradle it was Line 12:

apply plugin: 'com.android.application'

1 android {
2    compileSdkVersion 25
3    buildToolsVersion '25.0.2'
4    defaultConfig {
5       applicationId 'com.example.hellojni'
6       minSdkVersion 23
7       targetSdkVersion 25
8       versionCode 1
9       versionName "1.0"
10      externalNativeBuild {
11          cmake {
12              arguments '-DANDROID_TOOLCHAIN=clang' --> gcc
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
    productFlavors {
        arm7 {
            // in the future, ndk.abiFilter might also work
            ndk {
                abiFilter 'armeabi-v7a'
            }
        }
        arm8 {
            ndk {
                abiFilters 'arm64-v8a'
            }
        }
        arm {
            ndk {
                abiFilter 'armeabi'
            }
        }
        x86 {
            ndk {
                abiFilter 'x86'
            }
        }
        x86_64 {
            ndk {
                abiFilter 'x86_64'
            }
        }
        mips {
            ndk {
                abiFilters 'mips', 'mips64'
            }
        }
        universal {
            ndk {
                abiFilters 'mips', 'mips64', 'x86', 'x86_64'
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
}

Build fails in Android Studio: CMAKE_C_COMPILER not set · Issue , Build command failed. Error while executing process C:\Users\Robert\AppData\Local\Android\Sdk\cmake\3.6. 4111459\bin\cmake.exe with arguments {-HC:\Users\Robert\Desktop\build_untitled\android-native-build\untitled\app -BC:\Users\Robert\Desktop\build_untitled\android-native-build\untitled\app\. this is more like compiler mis-match: cmake tries to generate a simple C/C++ program and compiling it to make sure the settings/compiling flags are correct.

I would recommend using GCC instead of clang for the time being because clang still does not contain all features. You can change your compiler by doing the following:

set(CMAKE_C_COMPILER /path-to-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc)

However, the darwin-x86_64 directory only exists if you are on a Mac. If you are on another platform, just use the directory that exists under the prebuilt folder.

CMake | Android NDK, The Android NDK supports using CMake to compile C and C++ code for your Note: If you are using Android Studio, go to Add C and C++ Code to Your If building from the command line, pass arguments to CMake with -D  Try to do this: Step 1: Safely delete the build folder from app directory. Step 2: In Android Studio, File -> Invalidate Caches / Restart. Step 3: Build -> Clean Project Then Build -> Rebuild Project . so build folder will be regenerated and hope so error is gone.

I found this Solution Online and this worked, however there was no explanation on how it worked: Remove the following block of code from you build.gradle file:

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

Cmake errors for Android Studio - Dolphin Forums, SIMPLE: Build command failed. SIMPLE: Error while executing process C:\​Android_Studio_SDK\cmake\3.6.4111459\bin\cmake.exe with  When I open a new project that support C++ in Android Studio, It only outputs "Hello C++",And I didn't modify any code. I have tried to change the version of Android Studio and SDK. But it always s

In case previous answer doesn't work for you, as it happened to me, try to fix permissions in the bin folder of cmake and for ndk. In my case: C:\android-sdk\cmake\3.6.4111459\bin and c:\android-sdk\ndk-bundle

In my case Users group did had no permissions so Android Studio wasn't able to run cmake. Make sure it has Read and execution permissions.

Android Build error - General, When the Project is opened the following: Build command failed. Error while executing process /opt/android-sdk/cmake/3.6.4111459/bin/cmake  I guess going to SDK Manager (down arrow icon on the upper main menu) -> System Settings -> Android Sdk -> On the Tabs choose "SDK Tools" -> Find checkitem with caption "Cmake". check it and press "Install" - can help

Android Studio how integrate NDK with Opencv, Build command failed. Error while executing process C:\Users\eliecer\AppData\​Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Failing to export Android due to CMake - Bug Reports, 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

Hi, I'm learning to use NDK, I've created a new project check the c++ support use c++ 11 option The generated project run fine and show the "hello from c++". Then I tried to change the code at native-lib.cpp from sample code of bitmap pl

Comments
  • I had this same issue, could you please post your CMakeLists.txt?
  • ok I edited the Post
  • What version of the NDK are you using? Some versions have limited support for the clang compiler.
  • I use 15.1.4119093
  • @rpurohit I am facing same issue. can you please help me on my question.stackoverflow.com/questions/51100111/….
  • This is a life-saver. It also worked for me. My advice is to try this first, then other things.
  • It didn't work for first time. But after downgrading NDK from version 17 to 15, downgrading kotlin 1.2.41 to 1.2.31 and clicking this option "Build -> Refresh Linked C++ Projects" works for me.
  • Thanks a lot! is the really life-saver. Worked for me in Windows 10.
  • In my case that gives "Could not get unknown property 'gcc' for object of type com.android.build.gradle.internal.dsl.ExternalNativeCmakeOptions." I can't believe how badly Google has gotten this.
  • You are a life saver!
  • Try running it at the beginning of CMakeLists.txt.
  • That dosen't worked for me The Error is still the Same so the command didn't worked :/
  • @Biskit1943 How to can I change compiler from clang to GCC? can you explain proper steps becuase I am facing same error?
  • @rpurohit I think this answer is outdated now