简体   繁体   English

如何解决gradle错误

[英]how to solve the gradle error

hello Im realy need some help to my project gradle... Im new in android studio and now I have problem with gradle. 你好,我真的需要一些帮助我的项目gradle ...我是android studio中的新手,现在我遇到了gradle问题。 hlep me please... 拜托我...

Its my gradle code (Project:) 它是我的gradle代码(项目:)

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
}

and my gradle (Module:app) 和我的gradle(Module: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'
}

and now my messages gradle Sync is 现在我的消息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>

now Im using Gradle 3.2.1 in local Please help me :( 现在我在本地使用Gradle 3.2.1请帮助我:(

Use gradle 3.1.2 , not 3.2.1 , unless you absolutely have to have 3.2.1 . 使用gradle 3.1.2 ,而不是3.2.1 ,除非您绝对必须拥有3.2.1

When I tried to build with gradle 3.2.1, it failed, saying this: 当我尝试使用gradle 3.2.1进行构建时,它失败了,说:

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

Looks like you're using a version of Gradle lower than 4.1. 看来您使用的Gradle版本低于4.1。 Change the distribution URL in your gradle-wrapper.properties as follows: 更改gradle-wrapper.properties的分发URL,如下所示:

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

To locate the gradle-wrapper.properties file, press ctrl + shift + N in Android Studio and type gradle-wrapper 要找到gradle-wrapper.properties文件,请在Android Studio中按ctrl + shift + N并键入gradle-wrapper

Change the dependencies as follows: 更改依赖关系,如下所示:

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
}

Currently Android studio 3.2 is not in stable state. 目前,Android Studio 3.2处于不稳定状态。 Its in canary release state. 其处于金丝雀释放状态。 So its gradle plugin is in alpha state 所以它的gradle插件处于alpha状态

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

This version of gradle plugin is available in Android Studio 3.2 Canary17 此版本的gradle插件在Android Studio 3.2 Canary17中可用

If you want to use stable version then download Android Studio 3.1.3 如果要使用稳定版本,请下载Android Studio 3.1.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM