【问题标题】:Duplicate entry error while generating signed apk生成签名的apk时重复输入错误
【发布时间】:2018-03-14 16:21:23
【问题描述】:

在 android 中构建已签名的 apk 时出现此错误。请帮我解决这个问题。

错误是:

错误:任务 ':app:transformClassesWithJarMergingForRelease' 执行失败。

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:android/support/compat/R$bool.class

app 级别的

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26

    defaultConfig {
        applicationId "com.glocar.dealers"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 3
        multiDexEnabled true
        versionName "1.1.1"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        useLibrary 'org.apache.http.legacy'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }
}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:26.0.0'
    compile 'com.android.support:support-v4:26.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    implementation 'com.android.support:support-vector-drawable:26.0.0'
    implementation 'com.roughike:bottom-bar:2.3.1'
    compile 'com.github.bumptech.glide:glide:4.1.0'
    compile 'com.android.support:recyclerview-v7:26.0.0'
    compile 'com.android.support:cardview-v7:26.0.0'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.makeramen:roundedimageview:2.3.0'
    // retrofit, gson
    compile 'com.google.code.gson:gson:2.6.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'


    //firebase
    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-crash:11.8.0'
  //  compile 'com.google.android.gms:play-services-location:11.8.0'
    compile 'com.google.android.gms:play-services:11.8.0'
    compile 'com.android.volley:volley:1.1.0'
    compile 'com.android.support:design:26.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.0'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
}
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.0.0'
            }
        }
    }
}
apply plugin: 'com.google.gms.google-services'

项目级别的

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:3.0.0'

        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }



    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

标签: android


【解决方案1】:

尝试删除此行:

implementation 'com.roughike:bottom-bar:2.3.1'

并尝试使用支持库中的BottomNavigationView 而不是这个库

【讨论】:

  • 更新@user9484702
【解决方案2】:

这个问题可能是因为以下依赖:

implementation 'com.roughike:bottom-bar:2.3.1'

如果你检查它的project build.gradlemodule build.gradle,你会发现它仍然使用支持库版本25.3.0 for com.android.support:appcompat-v7com.android.support:design

因此,您需要排除两个支持库:

implementation ("com.roughike:bottom-bar:2.3.1") {
    exclude group: 'com.android.support'
    exclude module: 'appcompat-v7'
    exclude module: 'design'
}

请注意,底栏库已弃用。

【讨论】:

  • 感谢问题已经解决。但问题不在于您提到的图书馆,而在于谷歌图书馆。我使用了一个谷歌服务捆绑库和一个用于谷歌登录的单独库,这会产生重复。而且我还使用更新的版本号更新每个库。这消除了问题并生成了签名的apk。感谢所有的人。
  • 这真是一个好消息!您可以创建一个新答案,也可以编辑我的答案,这对遇到相同问题的每个人都有帮助;)
【解决方案3】:

将版本 [26.0.0] 更新到某个新版本,所有支持的依赖项必须具有相同的版本然后清理项目并再次运行

【讨论】:

    【解决方案4】:

    我通过更新每个库的更新版本来摆脱这个问题。 以前我使用谷歌捆绑库+谷歌单独库进行登录,这会产生重复。所以我删除了捆绑库并使用单独的库进行谷歌登录,然后清理项目 就是这样。

    【讨论】:

      猜你喜欢
      • 2016-11-11
      • 2023-03-13
      • 2017-02-15
      • 2016-08-08
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2023-04-06
      相关资源
      最近更新 更多