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 com
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"
}
}
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.
@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'
}
I tried the solutions provided above but no luck. Then I changed the path of OpenCV_DIR which was set in the CMakeLists.txt file and it worked. My project was not pointing to the right path, which was causing the error. Make sure you have provided the right path in your CMakeLists.txt file.
For example :
set(OpenCV_DIR "...../OpenCV_Android/install/sdk/native/jni/abi-arm64-v8a")
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
I find this way can work:
not need delete below:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
this is useful .and your project just less the ninja file .
you can fllow this way can build successful!
here is the result:
Make 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.
you should install ninja