无法找到com.android.tools.build:gradle:3.0.1。

15

当我尝试使用Gradle Wrapper构建我的项目时,出现以下错误:

./gradlew

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all files for configuration ':app:classpath'.
   > Could not find com.android.tools.build:gradle:3.0.1.
     Searched in the following locations:
         https://maven.fabric.io/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
         https://maven.fabric.io/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
     Required by:
         project :app

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

这个项目在Android Studio中可以成功构建。

我已经检查了thisthis,但我正在使用gradle wrapper版本4.1,已添加google()存储库,并尝试设置android.enableAapt2=false。还有其他提示吗?谢谢。

我的根build.gradle文件:

 // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.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-wrapper.properties 文件:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

更新:Gabriele是正确的。我需要在app/build.gradle文件中也添加仓库:

...
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}
...

我猜我对这个语句感到困惑:"要将其中一个库添加到您的构建中,请在顶级build.gradle文件中包含Google的Maven存储库",它在这里


你是在尝试使用Fabric吗? - Ergin Ersoy
22
在 app/build.gradle 文件的 buildscript 块中添加 google() 仓库。 - Gabriele Mariotti
1
谢谢 @GabrieleMariotti!就是这个。 - FGarcia
3个回答

23

我只想留下一个额外的提示。当我安装Android Studio时,我在某个地方读到建议保留这个配置(带有“+”符号)。

build.gradle(项目)

dependencies {
        classpath 'com.android.tools.build:gradle:+'
        .....
        #more lines here
}

然而,我正在使用的项目使用了一个旧版本的gradle,而这行代码总是请求最新版本。花了我一段时间才弄清楚。


谢谢,这解决了我的问题,但是背后的逻辑是什么?你能再多解释一下吗? - Pranav P

0

这是我解决问题的方法。 更改根build.gradle文件:

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

    .....
        //other codes here
    }

0

检查你在 Android Studio 上的代理设置

文件 > 设置 > 外观

&

行为 > 系统设置 > HTTP 代理

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接