如何解决gradle错误

时间:2018-06-10 12:14:39

标签: android gradle android-gradle build.gradle

你好我真的需要一些帮助我的项目gradle ... 我是android studio的新手,现在我有gradle的问题。 请告诉我......

我的gradle代码(Project:)

buildscript {

    repositories {
        apply plugin: 'java'
        apply plugin: 'announce'
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

和我的gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.shoaib.newsletters"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '27.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.tomerrosenfeld.customanalogclockview:custom-analog-clock-view:1.1'
    compile 'com.android.volley:volley:1.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
}

现在我的消息是gradle Sync

Error:(7, 0) Gradle DSL method not found: 'google()'
Possible causes:<ul><li>The project 'NewsLetters' may be using a version of Gradle that does not contain the method.
<a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

现在我在本地使用Gradle 3.2.1 请帮帮我:(

3 个答案:

答案 0 :(得分:0)

使用gradle 3.1.2,而不是3.2.1,除非您必须拥有3.2.1

当我尝试使用gradle 3.2.1构建时,它失败了,这样说:

  

找不到com.android.tools.build:gradle:3.2.1。

答案 1 :(得分:0)

看起来您使用的Gradle版本低于4.1。更改gradle-wrapper.properties中的分发网址,如下所示:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip

要找到gradle-wrapper.properties文件,请按ctrl + shift + N进入Android Studio并键入gradle-wrapper

更改依赖关系,如下所示:

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'

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

答案 2 :(得分:0)

目前Android studio 3.2尚未处于稳定状态。它处于金丝雀释放状态。 所以它的gradle插件处于alpha状态

classpath 'com.android.tools.build:gradle:3.2.0-alpha17'

这个版本的gradle插件可在Android Studio 3.2 Canary17中找到

如果您想使用稳定版本,请下载Android Studio 3.1.3