Guava library duplicate entry error

2019-07-04 05:30发布

问题:

I am trying to use guava library in my application. But I am also using chromium_webview project from github. This webview project contains guava library.

And I get the following error:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException: duplicate entry: com/google/common/annotations/GwtIncompatible.class

I've looked at this and this answers already and nothing seems to work.

Here's my module's build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "my.package.name"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    dexOptions {
        incremental true
        javaMaxHeapSize "2048M"
        jumboMode = true
    }

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

dependencies {
    compile files('libs/svgAndroid2-3Jan2014.jar')
    compile project(':chromium_webview')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.guava:guava:18.0'
}

I've tried the exclude method on the chromium_webview project like this:

compile (project(':chromium_webview')) {
    exclude group: 'com.google.guava', module: "guava_javalib.jar"
}

and like this:

compile (project(':chromium_webview')) {
    exclude module: "guava_javalib.jar"
}

Can I not use the same library again?
Is there a way to use the same library for both modules?

// ======================= EDIT:

Like @petey's comment mentioned, I tried removing just the guava library from my module and my module doesn't read the library in another module.

compile 'com.google.guava:guava:18.0'

that's the line I tried removing.

Any ideas will be really appreciated.
Thank you!!

回答1:

I actually did fix this problem, forgot to post it.

So the issue here was I was using maven/gradle dependency in my project BUT the chromium_webview library was using an actual JAR file as a library.

I modified the library to use the maven/gradle dependency. Android Studio and Gradle did all the work for me and excluded the necessary classes.

So make sure they both (library and your module) use the same method.
compile 'com.google.guava:guava:18.0'

I really hope this helps someone.
Thank you.