Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Your project contains C++ files but it is not using a supported native build

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

like image 736
Zikô'w Bàhà'Llôu Avatar asked Jan 22 '17 13:01

Zikô'w Bàhà'Llôu


2 Answers

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:

  1. In your project pane, right-click on your module, and select Link C++ Project with Gradle.
  2. 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

like image 92
Janman Avatar answered Oct 30 '22 09:10

Janman


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.

  1. 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.

  2. 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.

    1. 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
        }
      }
      
    2. 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.

    3. Another alternative is to add android.useDeprecatedNdk=true to gradle.properties. It is not clear, though, how long this flag will be working.

like image 14
Alex Cohn Avatar answered Oct 30 '22 08:10

Alex Cohn