Error:Execution failed for task ':app:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system. Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
Screenshot
It seems that you already have the C++ code, and the Makefiles in the project directory, in which case, you simply have to link Gradle to the native library:
From the drop-down select either CMake or ndk-build, depending on your project
a. If you selected CMake, specify the CMakeLists.txt script in your project
b. If you selected ndk-build, specify the Android.mk.
Source: https://developer.android.com/studio/projects/add-native-code.html#existing-project
The Android plugin these days shows a better explanation.
* What went wrong:
Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration. For more information, go to: http://d.android.com/r/studio-ui/add-native-code.html
Alternatively, you can use the experimental plugin: https://developer.android.com/studio/build/experimental-plugin.html.
There are essentially two options: either to use the integrated externalNativeBuild, or to disable it.
The best approach for the first option was described by Janman here.
I would not recommend using the experimental plugin these days, because I believe that ndk-build integration is much more powerful. But simple projects may be easier to maintain with the experimental plugin.
Alternatively, you can choose for some reason to build the native libraries outside the Android Studio. To prevent the error message, I know three options.
You can disable the gradle task: in build.gradle, add
tasks.all { task ->
if (task.name.startsWith('compile') && task.name.endsWith('Ndk')) {
task.enabled = false
}
}
You can hide the cpp files from Android Studio, e.g.
sourceSets {
main {
jni.srcDirs = []
}
}
The drawback of this approach is that the cpp files are not indexed by Android Studio.
Another alternative is to add android.useDeprecatedNdk=true
to gradle.properties. It is not clear, though, how long this flag will be working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With