依赖关系是最新的,但Gradle认为不是

时间:2018-09-29 17:50:34

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

当我使用最新版本和相同版本时,为什么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

3 个答案:

答案 0 :(得分: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'
}

答案 1 :(得分:0)

在终端上执行./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

答案 2 :(得分:0)

一个人也可以从依赖项中排除版本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以查看其来源。

相关问题