1. 程式人生 > >Error:Execution failed for task ':app:compileDebugNdk'. > Error: Your project contains C++ files but

Error:Execution failed for task ':app:compileDebugNdk'. > Error: Your project contains C++ files but

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. For more information, go to:
   https://d.android.com/r/studio-ui/add-native-code.html
  Alternatively, you can use the experimental plugin:

   https://developer.android.com/r/tools/experimental-plugin.html

Android studio3.0 開發jni時遇到的

原因:在app的build.gradle中沒用配置cmake

android {
    ...
    defaultConfig {
        ....

        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -D__CORRECT_ISO_CPP_WCHAR_H_PROTO"
            }
//            ndk {
//                abiFilters "armeabi", "armeabi-v7a"
//            }
        }
    }
    buildTypes {
       ...
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}