Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method externalNativeBuild() for arguments

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

like image 628
MinionDeveloper Avatar asked Sep 15 '16 08:09

MinionDeveloper


2 Answers

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'
}
like image 193
Dennis Shtatnov Avatar answered Nov 19 '22 01:11

Dennis Shtatnov


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'
    }
  }
}
like image 2
clemens Avatar answered Nov 19 '22 01:11

clemens