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)
I encountered this problem because I set the wrong path of
native-lib.cpp
. After changingto
it worked again.
By the way, this is part of my project's structure.
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.
Build -> Refresh Linked C++ Projects resolved this error for me.
@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:
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:
This error sometimes occurs when you upgrade gradle or other dependencies. a simple solution is Build > "Refresh linked C++ project" and after that rebuilding your project. everything goes right