android - 使用支持lib依赖性v7:26.1.0时发生Gradle dex问题

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

您好,我的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向我发出此警告:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.0, 26.1.0. Examples include com.android.support:recyclerview-v7:27.1.0 and com.android.support:animated-vector-drawable:26.1.0



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

我也看到此错误:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

最佳答案

Android Studio警告

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.0, 26.1.0. Examples include com.android.support:recyclerview-v7:27.1.0 and 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版本。



compileSdkVersiontargetSdkVersion更新为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:designcom.android.support:appcompat-v7com.android.support:support-v4具有传递依赖关系,因此,如果您声明appcompat-v7依赖关系,则不必手动声明support-v4design依赖关系。

关于android - 使用支持lib依赖性v7:26.1.0时发生Gradle dex问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49806622/

相关文章:

java - 无法从android中的tomcat服务器访问我的WSDL文件

android - 我怎样才能运行我的安卓应用程序?

android - 升级 gradle 版本后,谷歌地图停止显示

gradle - Gradle Sonarqube插件在Gradle版本2.13中出现 “Incompatible version 1007”失败

java - 使用 HashMap 对 ArrayList 进行字母数字排序

java - 为什么 Canvas 在实时绘制值图时绘制速度很慢?

android - 离线 Maven 仓库中缺少 Gradle 插件

java - Gradle P4Java java.net.SocketTimeoutException : Read timed out

groovy - Gradle Thrift 插件示例

android - OpenGL ES 2.0 中的纹理图集