Getting Error “Gradle DSL method not found: 'c

2019-01-07 20:44发布

Error after resolutionproject is staymax2 build.gradle files that i am working on To add V4 support libraries to android studio, i followed this document:https://developer.android.com/tools/support-library/setup.html#libs-without-res but I get an error. Here is what i did

  1. SDK manager> Installed Android Support Library and Android Repository.
  2. Go to Build.Gradle and added the line as given in the dcoument. Build.Gradle now looks like this:

// 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:0.13.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
    dependencies {

        compile "com.android.support:support-v4:18.0.+"
    }
}

}

Then, I get a popup that suggest that I sync gradle. When i sync Gradle, i get this error:

Error:(20, 0) Gradle DSL method not found: 'compile()' Possible causes:

  • The project 'staymax' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • Am i missing any step? Please suggest.

    Build.Gradle(app)

    apply plugin: 'com.android.application'
    
    android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"
    
    defaultConfig {
        applicationId "com.appt.shreyabisht.staymax"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
     }
    }
    
    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    }
    

    10条回答
    beautiful°
    2楼-- · 2019-01-07 21:22

    Just delete the method.

    //DELETE THIS LINES:
    android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'
    }
    

    Try to compile again. It should work now.

    Source : https://medium.com/@marcuspereira/solving-the-gradle-dsl-method-not-found-android-in-android-studio-6e5ab499bd3#.u1lxecq41

    查看更多
    三岁会撩人
    3楼-- · 2019-01-07 21:24

    Make sure you have a settings.gradle file in your project. Adding that solved the problem of Error:Gradle DSL method not found: 'minSdkVersion()' for me.

    查看更多
    狗以群分
    4楼-- · 2019-01-07 21:27

    I have the same issue, and the bug is my build.gradle of application level has dependencies of my submodules. Means

    dependencies {
       compile project(':library')
      compile project(':MPChartLib')
    }
    

    I have just remove the two line inside the dependencies braces and it is able to start syncing.

    查看更多
    Animai°情兽
    5楼-- · 2019-01-07 21:34

    Deleting .gradle in my project folder did the job for me.

    查看更多
    登录 后发表回答