如何在使用“classpath”com.android.tools.build:gradle:2.3.3'时修复build.gradle错误

时间:2017-08-04 06:39:49

标签: android android-gradle

这是我的android gradle文件。我收到错误的android gradle插件,它不包含该方法(例如,在1.1.0中添加了'testcompile')。我该如何解决这个问题。

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.xxx.xxxx"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.google.android.gms:play-services-auth:9.2.1'
    classpath 'com.android.tools.build:gradle:2.3.3'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
    testCompile group: 'junit', name: 'junit', version: '4.+'
    compile 'com.android.support.test:runner:0.5'
}

错误

enter image description here

3 个答案:

答案 0 :(得分:1)

现在修正后的构建。 gradle看起来像这样,现在我认为错误是"错误:(20,0)未找到Gradle DSL方法:' classpath()' 可能的原因:

  • 项目' WeatherApp'可能正在使用不包含该方法的Android Gradle插件版本(例如,在1.1.0中添加了' testCompile')。 将插件升级到版本2.3.3并同步项目
  • 项目' WeatherApp'可能正在使用不包含该方法的Gradle版本。 打开Gradle包装器文件
  • 构建文件可能缺少Gradle插件。 申请Gradle插件
  • "

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 25
        buildToolsVersion "26.0.1"
        defaultConfig {
            applicationId "com.xx.xxxxx"
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:2.3.3'
            }
        }
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        compile 'com.facebook.android:facebook-android-sdk:[4,5)'
        compile 'com.google.android.gms:play-services-auth:9.2.1'
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.3.1'
        compile 'com.android.support:design:25.3.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
        testCompile group: 'junit', name: 'junit', version: '4.+'
        compile 'com.android.support.test:runner:0.5'
    }
    

    答案 1 :(得分:0)

    dependencies区块中,您必须删除此行

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

    此行应在buildscript块中使用,例如:

    buildscript {
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
        }
    }
    

    答案 2 :(得分:0)

    从那里删除classpath 'com.android.tools.build:gradle:2.3.3'并将其添加到您的顶级build.gradle文件中。

    buildscript {
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
        }
    }