【问题标题】:Could not find com.android.tools.build:gradle:3.0.1找不到 com.android.tools.build:gradle:3.0.1
【发布时间】:2018-07-09 11:29:22
【问题描述】:

当我尝试使用 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 file 中添加存储库:

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

我想我对here 中的这句话感到困惑“要将其中一个库添加到您的构建中,请在您的顶级 build.gradle 文件中包含 Google 的 Maven 存储库”

【问题讨论】:

  • 你要使用织物吗?
  • 在 app/build.gradle 文件中的 buildscript 块中添加 google() repo
  • 感谢@GabrieleMariotti!就是这样。

标签: android gradle


【解决方案1】:

只是想留下一个额外的小费。当我安装 Android Studio 时,我在某处读到建议保留此配置(带有“+”符号)

build.gradle(项目)

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

但是,我正在使用的项目使用旧版本的 gradle,并且此行始终要求最新版本。我花了一段时间才弄明白。

【讨论】:

  • 谢谢,它解决了我的问题,但这背后的逻辑是什么?能多解释一下吗?
【解决方案2】:

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

文件 > 设置 > 外观

&

行为 > 系统设置 > HTTP 代理

【讨论】:

    【解决方案3】:

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

    dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
    
        .....
            //other codes here
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-05
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      相关资源
      最近更新 更多