5

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

3 回答 3

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'
}
于 2018-09-29T19:14:10.523 回答
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

于 2018-09-29T17:57:09.030 回答
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以查看它的来源。

于 2018-09-29T19:02:25.733 回答