[android] 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'
    

    The answer is


    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'
    

    This error appear because the compiler could not found "my-upload-key.keystore" file in your project

    After you have generated the file you need to paste it into project's andorid/app folder

    this worked for me!


    guys. I had the same problem before when I'm trying import a .aar package into my project, and unfortunately before make the .aar package as a module-dependence of my project, I had two modules (one about ROS-ANDROID-CV-BRIDGE, one is OPENCV-FOR-ANDROID) already. So, I got this error as you guys meet:

    Error:Could not find method android() for arguments [org.ros.gradle_plugins.RosAndroidPlugin$_apply_closure2_closure4@7e550e0e] on project ‘:xxx’ of type org.gradle.api.Project.
    

    So, it's the painful gradle-structure caused this problem when you have several modules in your project, and worse, they're imported in different way or have different types (.jar/.aar packages or just a project of Java library). And it's really a headache matter to make the configuration like compile-version, library dependencies etc. in each subproject compatible with the main-project.

    I solved my problem just follow this steps:

    ? Copy .aar package in app/libs.

    ? Add this in app/build.gradle file:

    repositories {
        flatDir {
            dirs 'libs' //this way we can find the .aar file in libs folder
        }
    }
    

    ? Add this in your add build.gradle file of the module which you want to apply the .aar dependence (in my situation, just add this in my app/build.gradle file):

    dependencies {
        compile(name:'package_name', ext:'aar')
    }
    

    So, if it's possible, just try export your module-dependence as a .aar package, and then follow this way import it to your main-project. Anyway, I hope this can be a good suggestion and would solve your problem if you have the same situation with me.


    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"
    

    Examples related to android

    Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

    Examples related to android-gradle-plugin

    WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Android Material and appcompat Manifest merger failed Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries Invoke-customs are only supported starting with android 0 --min-api 26 error: resource android:attr/fontVariationSettings not found Exception : AAPT2 error: check logs for details Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)

    Examples related to build.gradle

    Android Material and appcompat Manifest merger failed Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Android dependency has different version for the compile and runtime Setting up Gradle for api 26 (Android) What's the difference between implementation and compile in Gradle? More than one file was found with OS independent path 'META-INF/LICENSE' Android Studio - Failed to notify project evaluation listener error Gradle error: Minimum supported Gradle version is 3.3. Current version is 3.2 All com.android.support libraries must use the exact same version specification DELETE_FAILED_INTERNAL_ERROR Error while Installing APK

    Examples related to android-studio-2.0

    Android Studio: /dev/kvm device permission denied Could not find method android() for arguments

    Examples related to android-studio-import

    Could not find method android() for arguments SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable