Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method android() for arguments

I've been trying to import a project to Android Studio and this is where I am stuck, there is a similar question on Stack Overflow but it did not provide a solution to my particular error.

This is my error log:

C:\<some location>\build.gradle  Error:(24, 1) A problem occurred evaluating root project '<project name>'. > Could not find method android() for arguments [build_4fli1jm76ubcnxesnhqnhie47$_run_closure3@6e71db85] on root project '<project name>'. Information:BUILD FAILED 

The Gradle sync messages are:

Error:(24, 0) Gradle DSL method not found: 'android()' Possible causes:

  • The project 'PoojaPeople' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • I'm not too sure where exactly this method android() is located. If it is the one located in Application's build.gradle file, I still don't exactly know where to go from here. Any help is appreciated.

    My build.gradle is

    buildscript {     repositories {         maven { url "http://dl.bintray.com/populov/maven" }         mavenCentral()     }      dependencies {         classpath 'com.android.tools.build:gradle:2.1.0'         // NOTE: Do not place your application dependencies here; they belong         // in the individual module build.gradle files     } } allprojects {     repositories {         maven { url "http://dl.bintray.com/populov/maven" }         mavenCentral()      } } task clean(type: Delete) {     delete rootProject.buildDir }  android {     compileSdkVersion 17     buildToolsVersion '23.0.0' } dependencies {     compile files('app/libs/junit-4.12-JavaDoc.jar') } apply plugin: 'maven' 
    like image 660
    user1528506 Avatar asked May 16 '16 09:05

    user1528506


    People also ask

    What version of Gradle do I have?

    In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.

    What is a build Gradle file?

    “build. gradle” are scripts where one can automate the tasks. For example, the simple task to copy some files from one directory to another can be performed by the Gradle build script before the actual build process happens.


    2 Answers

    You are using the wrong build.gradle file.

    In your top-level file you can't define an android block.

    Just move this part inside the module/build.gradle file.

    android {     compileSdkVersion 17     buildToolsVersion '23.0.0' } dependencies {     compile files('app/libs/junit-4.12-JavaDoc.jar') } apply plugin: 'maven' 
    like image 143
    Gabriele Mariotti Avatar answered Sep 21 '22 11:09

    Gabriele Mariotti


    My issue was inside of my app.gradle. I ran into this issue when I moved

    apply plugin: "com.android.application" 

    from the top line to below a line with

    apply from: 

    I switched the plugin back to the top and violá

    My exact error was

    Could not find method android() for arguments [dotenv_wke4apph61tdae6bfodqe7sj$_run_closure1@5d9d91a5] on project ':app' of type org.gradle.api.Project. 

    The top of my app.gradle now looks like this

    project.ext.envConfigFiles = [         debug: ".env",         release: ".env",         anothercustombuild: ".env", ]   apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" apply plugin: "com.android.application" 
    like image 20
    Jacksonkr Avatar answered Sep 19 '22 11:09

    Jacksonkr