【问题标题】:Dependencies are up-to-date but Gradle thinks not依赖项是最新的,但 Gradle 认为不是
【发布时间】:2018-09-29 17:50:34
【问题描述】:

为什么当我使用最新的相同版本时,Gradle 会给出这个关于依赖项的错误?这只是今天才开始,我不知道如何解决这个问题:

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 28.0.0、26.1.0。示例包括 com.android.support:animated-vector-drawable:28.0.0 和 com.android.support:support-media-compat:26.1.0

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:animated-vector-drawable-v7:28.0.0'
    implementation 'com.android.support:support-media-compat-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
}

ʍѳђઽ૯ท的建议

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.

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

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

BUILD FAILED in 2s

【问题讨论】:

标签: android android-gradle-plugin android-support-library gradle-dependencies


【解决方案1】:

也许这是因为支持库版本 28 没有任何库调用它

implementation 'com.android.support:animated-vector-drawable-v7:28.0.0'

implementation 'com.android.support:support-media-compat-v7:28.0.0'

或者这可能是因为您使用的是支持库版本 28,但 targetSdkVersion 低于版本 28。

(在 Android Studio v:3.1.4 中)如果您想在项目中添加另一个库,请使用以下 URL

(from toolbar) file \ Project Structure ... \ (from left window : under modules) app \ Dependencies \ (use green plus)

这项工作对我来说:在 build.gradle (Project Gradle) 中添加这一行

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "your project"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'junit:junit:4.12'
    implementation 'com.android.support:support-v13:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:mediarouter-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:design:28.0.0'
}

【讨论】:

  • implementation 'com.android.support:support-v4:28.0.0' 成功了,tnx!
【解决方案2】:

在终端上执行./gradlew app:dependencies 将显示不同版本的依赖关系。要轻松解决此问题,只需在您的 Build.gradle 中添加旧的且版本不同的依赖项(与其他相关的) 依赖项。

如果您坚持错误,它将显示哪个依赖项是旧的,然后您可以看到版本之间的差异。

例如,如果您像其他相关依赖项一样将其添加为最新版本,它将被修复:

implementation 'com.android.support:support-media-compat:28.0.0' // just like the other related dependencies versions.

在您的情况下,其中之一是使用26.1.0 版本:

找到版本28.0.0、26.1.0

【讨论】:

  • 运行./gradlew app:dependencies 对我不起作用。查看我发布的错误。
  • 我的意思是,如果您将鼠标移到错误的红线上,它应该会在您的依赖项中显示红线错误,它应该显示哪些依赖项存在此问题。但是,您的 gradle 似乎有问题,请检查:discuss.gradle.org/t/… 尝试删除:.gradle 文件夹,然后重建并运行该命令以查看依赖关系树。 而且命令是正确的。
【解决方案3】:

也可以从依赖项中排除版本26.1.0,但这里是如何强制执行28.0.0

configurations.all() {
    resolutionStrategy.force "com.android.support:support-media-compat:28.0.0"
}

这可能来自:

implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.android.gms:play-services-maps:15.0.1"

从项目的根目录运行./gradlew app:dependencies,看看它来自哪里。

【讨论】:

    猜你喜欢
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2023-02-24
    相关资源
    最近更新 更多