android错误:Gradle sync失败:未找到Gradle DSL方法:' classpath()'

时间:2016-05-01 06:44:04

标签: java android android-gradle build.gradle android-studio-2.1

嗨我是Android工作室的新手,在从android studio 1.4更新到2.1之后,当我尝试同步我的项目时,我收到以下构建错误:

Gradle sync failed: Gradle DSL method not found: 'classpath()'

以下是build.gradle:

    apply plugin:'com.android.application'

android {
    compileSdkVersion  23
    buildToolsVersion  "23.0.3"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId  "android.arisa.---------"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        //multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
        exclude module: 'support-v4'
    }
    compile('com.afollestad.material-dialogs:core:0.8.1.0@aar') {
        transitive = true
    }
    compile('com.afollestad.material-dialogs:commons:0.8.1.0@aar') {
        transitive = true
    }
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.google.android.gms:play-services-maps:7.8.0'
    compile 'com.google.android.gms:play-services-location:7.8.0'
    //compile 'com.android.support:multidex'
    //compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    //compile 'com.mcxiaoke.volley:library:1.+'
    compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/.idea/libraries/jsoup-1.8.3.jar')
    compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/jsoup-1.8.3.jar')
    compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/libraries/jsoup-1.8.3.jar')
    compile 'com.google.android.gms:play-services:8.3.0'
}
repositories {
    jcenter()
}
//repositories {
//    maven { url "https://jitpack.io" }
//}

和gradle-wrapper.properties是:

#Sat Apr 30 11:59:41 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip

我怎么能纠正这个?(请帮帮我)

编辑:编辑成绩后,我的android gradle是:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "android.arisa.kalahroodfinal"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
        exclude module: 'support-v4'
    }
    compile('com.afollestad.material-dialogs:core:0.8.1.0@aar') {
        transitive = true
    }
    compile('com.afollestad.material-dialogs:commons:0.8.1.0@aar') {
        transitive = true
    }
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.google.android.gms:play-services-maps:7.8.0'
    compile 'com.google.android.gms:play-services-location:7.8.0'
    compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/.idea/libraries/jsoup-1.8.3.jar')
    compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/jsoup-1.8.3.jar')
    compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/libraries/jsoup-1.8.3.jar')
    compile 'com.google.android.gms:play-services:8.3.0'
}

但我有新的错误:

Error:(43, 13) Failed to resolve: com.afollestad.material-dialogs:commons:0.8.1.0
Error:(40, 13) Failed to resolve: com.afollestad.material-dialogs:core:0.8.1.0

2 个答案:

答案 0 :(得分:0)

尝试删除classpath 'com.android.tools.build:gradle:2.1.0'字符串。

我还建议您在Android Studio 2.1中创建新项目,并将IDE生成的gradle文件与您的文件进行比较。

答案 1 :(得分:0)

您正在使用

  classpath 'com.android.tools.build:gradle:2.1.0'

在错误的街区。

在顶级build.gradle文件中(在项目的根目录中)更多

// 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:2.1.0'
    }
}

要解决库材料对话框的问题,您必须添加从中下载依赖项的存储库:

在您的顶级build.gradle文件中添加jitpack repo:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}