【问题标题】:Updating Gradle Dependencies in Android Projects在 Android 项目中更新 Gradle 依赖项
【发布时间】:2017-11-30 09:54:28
【问题描述】:

我时不时地在更新 gradle 文件中的支持库依赖项时遇到同样的问题。

目前我使用的是 26.0.0-alpha1 版本

compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:support-core-utils:26.0.0-alpha1'
compile 'com.android.support:support-v4:26.0.0-alpha1'

另外我的设置是这样的

compileSdkVersion 26
buildToolsVersion '26.0.2'
minSdkVersion 21
targetSdkVersion 26

更新我使用的存储库

buildscript {
        repositories {
            jcenter()
            maven { url "https://maven.google.com" }
        }
    }

今天我更新了所有工具,现在所有支持库都标有消息

A newer version of com.android.support:recyclerview-v7 than 26.0.0-alpha1 is available: 26.1.0

所以我将库的版本更改为 26.1.0

compile 'com.android.support:recyclerview-v7:26.1.0'

但这会导致错误

Failed to resolve: com.android.support:recyclerview-v7:26.1.0

所以我将设置更改为

buildToolsVersion '26.1.0'

但这会导致错误

Failed to find Build Tools revision 26.1.0
Install Build Tools 26.1.0 and sync project

所以我点击“安装...”并导致错误

All packages are not available for download!
The following packages are not available:
- Package id build-tools;26.1.0

感觉就像 Android Studio 在欺骗我。有人可以告诉我更新库的有效方法吗?

【问题讨论】:

  • maven { url "https://maven.google.com" }
  • 这个我已经用过了(加到帖子里了)
  • 将其标记为重复是错误的。另一个问题类似,但主题不同。
  • 重新打开您的问题。

标签: android android-gradle-plugin build.gradle android-support-library


【解决方案1】:

用这个更新你的项目级 build.gradle 文件

buildscript {
    repositories {
        jcenter()
        google()
    }
    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 {
        jcenter()
    }
}

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

您的 buildToolVersion 应该是这样的:buildToolsVersion '26.0.2' 或更新到最新的27.0.1

【讨论】:

    【解决方案2】:

    无法解决:com.android.support:recyclerview-v7:26.1.0

    您必须在您的repositories 块中添加google maven repo。您只在buildscript 块下的块中添加它,它是不同的。

    allprojects {
        repositories {
            jcenter()
            maven { url "https://maven.google.com" }
        }
    }
    

    未能找到构建工具修订版 26.1.0

    它不存在。使用现有版本。
    你可以check here

    【讨论】:

    • 感谢您的链接。这很有帮助。您提到 26.1.0 不存在,但为什么 Android Studio 建议使用 26.1.0 版本?这对我来说毫无意义/让我恼火。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2013-01-30
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 2014-04-24
    相关资源
    最近更新 更多