【问题标题】:Gradle dex issue when using support lib dependency v7:26.1.0使用支持库依赖 v7:26.1.0 时的 Gradle dex 问题
【发布时间】:2018-04-12 22:10:22
【问题描述】:

您好,我的build.gradle 文件有问题:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.dell"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    implementation 'com.google.firebase:firebase-firestore:12.0.1'
    implementation 'com.firebaseui:firebase-ui-firestore:3.3.0'
    implementation 'hanks.xyz:htextview-library:0.1.5'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Android Studio 给了我这个警告:

所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 27.1.0、26.1.0。例子包括 com.android.support:recyclerview-v7:27.1.0 和 com.android.support:animated-vector-drawable:26.1.0

有人可以帮帮我吗?我不知道该怎么办。我什至尝试将其设置为 v 27。我什至删除了它,但它仍然没有解决我的问题。

我也看到了这个错误:

错误:任务执行失败 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 索引

【问题讨论】:

  • 有什么问题?
  • 问题说我的recycle view是v7 27,支持是version 26,不知道怎么解决
  • 请发布完整的 gradle 文件
  • @LeviAlbuquerque 我有一个新问题,如果你能看一下,我将不胜感激

标签: android android-studio gradle android-gradle-plugin


【解决方案1】:

Android Studio 警告

所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 27.1.0、26.1.0。例子包括 com.android.support:recyclerview-v7:27.1.0 和 com.android.support:animated-vector-drawable:26.1.0

问题

您的一个依赖项 (com.firebaseui:firebase-ui-firestore:3.3.0) 在 com.android.support:recyclerview-v7:27.1.0 上有一个 transitive dependency。同时,您在构建文件中手动声明的支持库使用版本26.1.0。

解决方案

将compileSdkVersion 和targetSdkVersion 更新为27,并将您的支持库更新为27.1.1

android {
    compileSdkVersion 27
    defaultConfig {
        targetSdkVersion 27
        ...
    }
    ...
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    ...
}

提示(可选)

由于com.android.support:design 对com.android.support:appcompat-v7 和com.android.support:support-v4 具有传递依赖关系,因此您不必手动声明appcompat-v7 或support-v4 依赖关系如果 您声明design 依赖关系.

【讨论】:

  • @ora 这个问题可能会有所帮助:stackoverflow.com/questions/47079113/…
  • 让我试试我会告诉你的
  • 您添加的库之一似乎使用了较新版本的 recyclerview。尝试将您的 compileSdkVersion 更新为 27,并将所有支持库依赖项更新为 27.1.1。
  • 我现在试试,让你知道
  • 此外,您可以删除 appcompat-v7 和 support-v4 支持库依赖项,因为 design 库依赖于这些库(称为传递依赖项)
猜你喜欢
  • 1970-01-01
  • 2014-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-29
  • 1970-01-01
  • 2016-07-26
  • 1970-01-01
相关资源
最近更新 更多