android - 无法解析com.android.tools.build:gradle:3.0.1;

标签 android gradle java-8

我在gradle-properties中使用它:

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

build.gradle:
**buildscript {
        repositories {
            google()
            mavenCentral()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath 'com.google.gms:google-services:3.0.0'
            // NOTE: Do not place your application dependencies here; they 
             //belong
            // in the individual module build.gradle files
        }
    }
    allprojects {
        repositories {
            jcenter()
             maven {
                url 'https://maven.google.com'
            }
        }
    }
    task clean(type: Delete) {
        delete rootProject.buildDir
    }**

我遇到此错误:
**failed org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
    org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.android.tools.build:gradle:3.0.1.
    org.gradle.api.resources.ResourceException: Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
    org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0`enter code here`.1.pom'.
    org.apache.http.conn.HttpHostConnectException: Connect to dl.google.com:443 [dl.google.com/172.217.160.238] failed: Connection timed out: connect
    java.net.ConnectException: Connection timed out: connect**

我已经用gradle 5.6.4更新了gradle.properties:
**distributionBase=GRADLE_USER_HOME
            distributionPath=wrapper/dists
            zipStoreBase=GRADLE_USER_HOME
            zipStorePath=wrapper/dists
            distributionUrl=https\://services.gradle.org/distributions/gradle- 
    5.6.4-all.zip**

并且我在gradle存储库中添加了maven {url“https://jitpack.io”}:
**buildscript {
        repositories {
            google()
            mavenCentral()
            jcenter()
            maven { url "https://jitpack.io" }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.6.1'
            classpath 'com.google.gms:google-services:3.0.0'
            // NOTE: Do not place your application dependencies here; 
           //they belong
            // in the individual module build.gradle files
        }
    }
    allprojects{
        repositories {
            jcenter()
            maven {
                url 'https://maven.google.com'
            }
            maven { url "https://jitpack.io" }
        }
    }
    task clean(type: Delete) {
        delete rootProject.buildDir
    }**

我已经设置了代理并进行了设置,但是问题仍然存在。

最佳答案

请尝试将分发网址用作:

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

并在build.gradle:project:
   buildscript {
        repositories {
            google()
            mavenCentral()
            jcenter()
            maven { url "https://jitpack.io" } // add this line.

        }
        dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
            classpath 'com.google.gms:google-services:3.0.0'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    allprojects {
        repositories {
            jcenter()
             maven {
                url 'https://maven.google.com'
            }
            maven { url "https://jitpack.io" } // add this line.

        }
    }
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

您需要添加maven { url "https://jitpack.io" } // add this line.在项目build.gragle中即可解决此问题。

关于android - 无法解析com.android.tools.build:gradle:3.0.1;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61359382/

相关文章:

gradle - 使用 maven-publish 插件签署 POM 文件

intellij-idea - 有没有办法创建一个跨多个 Gradle 项目作为模块的联合 Intellij 项目

java - 函数可以用作输入或从其他函数返回是什么意思?

关于清除链表的 Java 最佳实践

android - 重启后广播接收器不重启

java - 如何将hashmap中的数据从json获取到适配器中?

android - 在 Android 中获取并显示相机 View 的部分区域

android - 使用@ org.parceler.Parcel后,Android Studio Gradle错误

java - 在 android 上具有授权的 HTTP POST 请求

java-8 - 如何在JOOQ中编写OPTIONAL where子句