Could not find method externalNativeBuild() for arguments
Asked Answered
P

3

13

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 =)

Promissory answered 15/9, 2016 at 8:27 Comment(2)
Did you put the externalNativeBuild inside of the android{} block?Norm
yes I did, so it can't be the error sourcePromissory
S
15

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'
}
Screening answered 19/9, 2016 at 22:7 Comment(1)
What about gradle:3.2.1? Still getting the error using this version.Worcester
T
3

Suggested by Kun Ming Xies answer, I have separated my cmake part in two to get rid of the annoying error:

Could not find method arguments() for arguments [-DREVISION=1.3.1] on object of type com.android.build.gradle.internal.dsl.CmakeOptions.

The first part in defaultConfig contains the configuration (command line arguments for CMake and C++ flags), and the second contains the path to CMakeLists.txt:

def revision = "1.3.1"
android {
  compileSdkVersion 25
  buildToolsVersion "25.0.2"

  defaultConfig {
    versionCode = ...
    versionName "${revision}"
    externalNativeBuild {
      cmake {
        arguments "-DREVISION=${revision}"
        cppFlags '-fexceptions', '-frtti', '-std=c++11'
      }
    }
  }

  buildTypes { }

  lintOptions { }

  externalNativeBuild {
    cmake {
      path 'CMakeLists.txt'
    }
  }
}
Titan answered 11/9, 2017 at 14:30 Comment(0)
W
1
android {
    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_TOOLCHAIN=clang'
            }
        }
    }
Wash answered 13/10, 2016 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.