Could not find method externalNativeBuild() for arguments

MinionDeveloper picture MinionDeveloper · Sep 15, 2016 · Viewed 20.2k times · Source

i'm trying to integrate the ndkBuild functionality into an existing android studio project, using the new android studio 2.2 , in order to enable c++ debugging etc. i have tried out one of the ndk example projects which android studio 2.2 offers, which works perfectly fine. However, when i try to run the gradle commands in my own project, i get this error message:

Error:(73, 0) Could not find method externalNativeBuild() for arguments [build_c6heui1f67l8o1c3ifgpntw6$_run_closure2$_closure9@4329c1c9] on project ':core' of type org.gradle.api.Project.

By following this description http://tools.android.com/tech-docs/external-c-builds i ended up with a gradle script which includes the following commands:

externalNativeBuild{
    ndkBuild{
        path "$projectDir/jni/Android.mk"
    }
}

externalNativeBuild {
    ndkBuild {
      arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
      abiFilters "armeabi-v7a", "armeabi","arm64-v8a","x86"
      cppFlags "-frtti -fexceptions"
    }
}

Did i perhaps miss out on something here with the project setup? I have set the Android NDK location properly under

File -> Project Structure ... -> SDK Location -> Android NDK location

in my android studio.

Anything else i might have forgotton?

Has anyone run into a similar problem before?

Advice would be much appreciated =)

Answer

Dennis Shtatnov picture Dennis Shtatnov · Sep 20, 2016

Just had this error myself. In your root build.gradle, make sure that gradle is set to at least version 2.2.0:

So you should have the following in buildscript {...}

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
}