【问题标题】:How to solve this error ( duplicate entry: com/google/gson/annotations/Expose.class? )如何解决此错误(重复条目:com/google/gson/annotations/Expose.class?)
【发布时间】:2017-08-31 20:41:00
【问题描述】:

每次我尝试构建 APK 时,都会一直显示此错误!?我已经尝试了网站上几乎所有提到的灵魂,但没有运气!

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

com.android.build.api.transform.TransformException: java.util.zip.ZipException:重复条目:com/google/gson/annotations/Expose.class

我的 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'


    lintOptions {
        quiet true
        abortOnError false
        ignoreWarnings true
    }
    configurations {
        all*.exclude group: 'commons-io'

    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'BinaryEncoder.java'
    }

    defaultConfig {
        applicationId "com.xxxx.xxxxx"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 3
        versionName "1.2"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
    sourceSets {
        main {
            java {
                exclude 'com.twilio:client-android:1.2.18.org.apache.http.lejacy.jar.org.apache.BinaryEncoder.java'
                exclude 'org.apache.commons.codec.BinaryEncoder.java'
            }
        }
        androidTest {
            java {
                exclude 'commons-codec-1.10/**'
            }
        }
    }

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

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
     compile('com.twilio:client-android:1.2.18') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compile project(':example')
    compile project(':zoomcommonlib')
    compile project(':zoommobilertc')

    compile("com.github.hotchemi:permissionsdispatcher:2.4.0") {
         exclude module: "support-v13"
    }

    compile('com.stripe:stripe-android:4.1.5') {
        transitive = true;
        exclude  group: 'com.google.code.gson', module: 'gson'
    }
    compile('com.squareup.retrofit:retrofit:1.9.0') {
        transitive = true;
        exclude  group: 'com.google.code.gson', module: 'gson'
    }

    compile 'com.google.android.gms:play-services-gcm:11.2.0'
     compile 'lib.kingja.switchbutton:switchbutton:1.1.3'
    compile 'com.orhanobut:hawk:2.0.1'
     compile 'com.afollestad:material-camera:0.4.4'
    compile 'com.werb.pickphotoview:pickphotoview:0.3.0'
     compile 'com.github.Kennyc1012:BottomSheet:2.3.4'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.android.support:design:26.0.1'
    compile 'com.android.support:cardview-v7:26.0.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.google.android.gms:play-services-identity:11.2.0'
    compile 'com.google.android.gms:play-services-plus:11.2.0'
    compile 'com.google.android.gms:play-services-maps:11.2.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
     compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.paypal.sdk:paypal-android-sdk:2.14.4'
    compile 'com.koushikdutta.ion:ion:2.1.8'
    compile 'com.afollestad.material-dialogs:core:0.8.6.0'
    compile 'com.amitshekhar.android:android-networking:1.0.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.android.support:support-v4:26.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.4.0'
 }

以下是我尝试过但不起作用的一些解决方案:

  1. 我已经添加了那些 transitive = true; exclude group: 'com.google.code.gson', module: 'gson' forretrofitandstripe` 依赖项

  2. 我删除了gson依赖

  3. 我想删除 gson 库的 jar 文件,但在 libs 文件夹中找不到它!?

  4. multiDexEnabled true 已添加,但无效

  5. 我已删除compile fileTree(dir: 'libs', include: ['*.jar'])

我认为这与 Zoom 模块或 Stripe 任何帮助有关.. !?

【问题讨论】:

    标签: java android gradle gson


    【解决方案1】:

    您可以尝试获取依赖树并找出它是哪个包。

    【讨论】:

    • 怎么做?
    • 如果你正在使用包装器,请尝试使用 gradle 依赖项或 gradlew。 Android 有 ./gradlew app:dependencies。但不确定它是否仍然是相同的命令。
    • 还是找不到包..!
    • 你的依赖树是什么样子的?
    • 我尝试从终端打印,这个错误显示:E:\****\*****>gradlew app:dependencies Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details FAILURE: Build failed with an exception. * Where: Build file 'E:\*****\****\app\build.gradle' line: 130 * What went wrong: Could not compile build file 'E:\*****\******\app\build.gradle'. > startup failed: build file 'E:\*******\******\app\build.gradle': 130: unexpected char: 0xFFFF @ line 130, column 2. } ^ 1 error
    【解决方案2】:

    在android studio终端执行

    ./gradlew clean
    

    并执行以下操作并重建

    尝试将此添加到您的依赖项中

    compile'com.android.support:multidex:1.0.1'
    

    在清单中添加这个

    android:name="android.support.multidex.MultiDexApplication" 
    

    在应用标签中

    【讨论】:

    • 你的 lib 文件夹中有什么。它是否包含 gson.jar 文件或任何相关的 jar 文件?尝试删除它并重建。
    • 尝试将此添加到您的依赖项compile 'com.android.support:multidex:1.0.1' 并在清单中添加此android:name="android.support.multidex.MultiDexApplication" 应用程序标签
    • 如果有帮助请告诉我:)
    • 它也不起作用,这是我的 libs 文件夹包含的内容image.ibb.co/k1UFBv/aaaaaaaaa.jpg
    【解决方案3】:

    我想通了,首先.. 无论如何感谢你们的帮助..!但我将此作为公认的答案,因为它对我有用!


    第 1 步 我使用 (Double Shift) 在整个项目中搜索了重复的类 它向我展示了哪个库也在使用同一个类..!就我而言,它是zoommobilertc

    第 2 步

    我尝试像这样排除该库的 gson 模块:

    compile project(':zoommobilertc'){
       exclude  group: 'com.google.code.gson', module: 'gson'
    }
    

    ..但它没有用,它给了我一个错误,我认为它与 exclude 有关。我尝试了一些解决方案,但没有运气!

    所以..我这样做了..

    • 打开项目视图
    • 打开外部库
    • 找到zoommobilertc 的库并展开其文件夹
    • 删除Gson显示的jar文件!

    第 3 步

    之后,我同步项目并尝试构建一个apk,但显示此错误:

    Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --multi-dex --main-dex-list E:\*****\*****\app\build\intermediates\multi-dex\debug\maindexlist.txt --output E:\*****\*****\app\build\intermediates\transforms\dex\debug\folders\1000\1f\main E:\*****\*****\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
    

    然后在搜索后我找到了解决方法:

    我在 android 部分的 build.gradle 文件中添加了这个:

    android{
    //..
     dexOptions {
            javaMaxHeapSize "4g"
        }
    //..
    }
    

    ..和 local.properties 文件中的这一行

    org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
    

    完成

    【讨论】:

      【解决方案4】:

      找出导致上述错误的依赖并排除gson 从您的依赖项如下,

      compile ('your_dependency'){
          exclude group : 'com.google.code.gson'
      }
      

      【讨论】:

        【解决方案5】:

        我的 libs 文件夹中有我的 gson.jar。
        我通过保留以下行来修复我的重复条目:
        implementation fileTree(dir: "libs", include: ["*.jar"])

        并在此处删除此条目:
        implementation 'com.google.code.gson:gson:2.8.7'

        【讨论】:

          猜你喜欢
          • 2017-03-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多