4

Any suggestions to fix this problem: I am getting this error in android studio after importing Project

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

  • The project 'LoginActivity' 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
  • // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.1.0'
        }
    }
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    android {
        compileSdkVersion 21
        buildToolsVersion '21.0.0'
        dexOptions {
            incremental true
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_6
            targetCompatibility JavaVersion.VERSION_1_6
        }
    }
    dependencies {
        compile 'com.android.support:support-v4:21.0.3'
        compile 'com.android.support:appcompat-v7:21.0.3'
    }
    apply plugin: 'eclipse'
    apply plugin: 'java'
    

    There is a bar notification which says: Gradle project sync failed. Basic fuctionality (eg: editing, debugging) will not work properly.

    Please help me to get rid of this problem. Thanks!

    silent_programmer
    • 768
    • 2
    • 8
    • 18
    • For me the response that solved the problem was other. Check this Out http://stackoverflow.com/questions/23409384/android-studio-build-script-error-unsupported-gradle-dsl-method-found-andro?lq=1 – Fidel Orozco Dec 30 '15 at 06:49

    3 Answers3

    4

    If you have an android block in your build script, you need one of the following two statements, depending on whether your module is an application module or a library module:

    apply plugin: 'com.android.application'
    

    or:

    apply plugin: 'com.android.library'
    

    Having said that, there are other problems with your build script. For one, this is a top-level build script (as you can see by the comment that says "Top-level build file where you can add configuration options..."), so it's likely that there isn't actually a top-level module for the android block to apply to, so adding the apply plugin statement may just lead to a different error. If that happens, remove the android block.

    Another issue is that you already have a apply plugin: 'java' statement in this build script. You can't use both the Java and the Android plugins in the same build script; they collide with each other.

    Scott Barta
    • 79,344
    • 24
    • 180
    • 163
    2

    Just delete this method from your root build.gradle

    android {
    compileSdkVersion 21
    buildToolsVersion '21.0.0'
    dexOptions {
        incremental true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    } }
    

    It should work after you compile again.

    k9x
    • 81
    • 5
    0

    if get error then check your gradle file version and remove other gradle dependancy like classpath 'com.android.tools.build:gradle:1.5.0' it may solve the problem

    Mahi
    • 1