【问题标题】:Could not find com.android.tools.build:gradle:3.5找不到 com.android.tools.build:gradle:3.5
【发布时间】:2017-04-19 13:32:31
【问题描述】:

我正在尝试将 gradle 从 1.3.1 更新到 3.5,因为我的一些依赖项需要 3.3 或更高版本。

我见过类似的问题,但没有一个有帮助。

build.gradle

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

gradle-wrapper.properties

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

当我尝试做任何事情(构建、清理等)时,我仍然得到这个:

Building and installing the app on the device (cd android && ./gradlew installDebug...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'chat'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.5.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.5/gradle-3.5.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.5/gradle-3.5.jar
     Required by:
         project :

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

BUILD FAILED

【问题讨论】:

  • 你找到解决办法了吗?

标签: android react-native


【解决方案1】:

要解决此问题,请检查您的 项目级别 build.gradle 文件中是否有 google() 存储库。

buildscript {
    repositories {
        jcenter()
        google() //HAVE YOU MISS IT?
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google() //HAVE YOU MISS IT?
    }
}

【讨论】:

  • 我还必须从存储库中删除它:mavenCentral()
  • 如果您是从非常旧的 maven 版本(低于 4)更新,google() 别名尚未包含,请改用maven { url "https://maven.google.com" }
【解决方案2】:

Android Plugin for Gradle 版本和所使用的 Gradle 版本之间存在差异。插件版本通常与您使用的 Android Studio 的版本号相匹配。请参阅documentation 了解更多信息。因此,如果使用最新的稳定版 Android Studio,目前应该是com.android.tools.build:gradle:2.3.1

还可以在 Android Studio 的“项目结构”窗口中查看和设置这些值。

【讨论】:

  • 如果我不使用 android studio?因为我没有
  • @stkvtflw,好吧,只需将classpath 'com.android.tools.build:gradle:3.5' 替换为classpath 'com.android.tools.build:gradle:2.3.1'
  • 正如 Egor 所提到的,只要您更新项目 build.gradle 文件以引用实际存在且与 Gradle 版本兼容的 Android Plugin for Gradle 版本,如我提供的链接所示,它应该工作。我只是展示了“项目结构”窗口作为替代方案,因为您似乎知道如何更新 build.gradle 文件中的值。
  • 2019:尝试将旧的 Eclipse ADT 项目导入 Android Studio 时出现此错误。 Android 插件版本是 3.5,所以我根据文档中的内容将 Gradle 版本更改为 5.4.1(请注意,它们在项目结构中的顺序已交换)。然后我必须在错误消失之前单击“添加 Google Maven 存储库并重新同步”或类似的东西。
  • Android Studio 是我在电梯中使用的最差的 IDE。每次有新版本时都会出现大量的兼容性问题。
【解决方案3】:

试试这个

  ** If you are using android studio 3.5 and your build.gradle(Project 
level) is=> classpath 'com.android.tools.build:gradle:3.5.1' or => 
classpath 'com.android.tools.build:gradle:3.5.1'.
than replace with *** 

   classpath 'com.android.tools.build:gradle:3.3.2' to 

    classpath 'com.android.tools.build:gradle:3.5.0' 

                   OR 
   classpath 'com.android.tools.build:gradle:3.5.1'

【讨论】:

    【解决方案4】:

    我在buildscriptallprojects 存储库中都有google() repo,但它仍然显示Could not find gradle-3.5.3 错误
    最后我添加了maven { url "https://maven.google.com" },它修复了错误!

    项目级build.gradle:

    buildscript {
        ext {
            buildToolsVersion = "29.0.2"
            minSdkVersion = 16
            compileSdkVersion = 29
            targetSdkVersion = 29
        }
        repositories {
            maven { url "https://maven.google.com" }  // <= this line
            google()
            jcenter()
        }
        dependencies {
            classpath("com.android.tools.build:gradle:3.5.3")
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            maven { url "https://maven.google.com" }  // <= this line
            mavenLocal()
            maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url("$rootDir/../node_modules/react-native/android")
            }
            maven {
                // Android JSC is installed from npm
                url("$rootDir/../node_modules/jsc-android/dist")
            }
    
            google()
            jcenter()
            maven { url 'https://www.jitpack.io' }
        }
    }
    

    【讨论】:

      【解决方案5】:

      您可能需要保存您的 build.gradle(无论出于何种原因,Android Studio 并不总是保存您的最新更改,因为我发现即使使用 Android Studio 3.5.3,即使我更改了 gradle 同步仍然失败classpath 行,它只在保存 build.gradle 文件后才获取新值)

      【讨论】:

        【解决方案6】:

        将版本代码从 2 更改为 2.1 后出现错误。 当我用 ctrl+shift+alt+s 打开构建时,我意识到添加 .1(十进制)会导致在右侧添加一个 $ 符号,因此构建失败。我选择使用没有小数位的数字并且它有效。 例如,我使用 3 作为 buildversion,因为我想升级 playstore 中的应用程序。

        【讨论】:

        • 如果您有新问题,请点击 按钮提出问题。如果有助于提供上下文,请包含指向此问题的链接。 - From Review
        • Suraj Kumar,我只是给出我的解决方案而不是问题。 Zubair,谢谢你的编辑,我的英语不是很好。
        猜你喜欢
        • 2021-12-16
        • 2019-05-12
        • 2019-11-06
        • 2019-12-27
        • 2020-02-08
        • 2017-04-11
        • 2018-09-05
        • 2019-09-24
        • 2021-03-12
        相关资源
        最近更新 更多