duplicate entry: com/android/volley/AuthFailureError.class while compiling project in android studio

I am using external libraries payu money sdk and linkedin-sdk, both uses volley libraries, which while compiling project gives duplicate entry of AuthFailureError.class

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

java.util.zip.ZipException: duplicate entry: com/android/volley/AuthFailureError.class"

i have also added following code to exclude module, but still same error

configurations{ all*.exclude module: 'com.android.volley' }

please help


Solution 1:

I stumbled upon this same error, and after reading this, I was able to solve it.

Try adding this line inside your app dir build.gradle file -

android{
configurations {
    all*.exclude group: 'com.android.volley'
}}

Hope this helps.

Solution 2:

I had this problem when I tried to generate the APK (release) and I solved it changing the linkedin-sdk build.gradle:

From:

dependencies {
    compile 'com.android.support:support-annotations:20.0.0'
    compile 'com.android.support:support-v4:21.0.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/volley.jar')
    androidTestCompile('junit:junit:4.12') }

To:

dependencies {
    compile 'com.android.support:support-annotations:20.0.0'
    compile 'com.android.support:support-v4:21.0.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.volley:volley:1.0.0'
    androidTestCompile('junit:junit:4.12') }

Solution 3:

Add multiDexEnabled true in the defaultConfig section of your gradle file

Then,

compile 'com.android.support:multidex:1.0.1' in your dependencies

Finally add below in your application class:

 @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

Also, check if you are using volley.jar in your libs folder. If so, delete that jar file, and compile again. Sometimes, jar dependencies conflicts with those compiled using remote source.

Solution 4:

This is an example how to exclude classes in dependencies when there is duplicate entry in gradle.

 compile ('com.google.api-client:google-api-client-android:1.17.0-rc') {
    exclude module: 'httpclient'
 }

or try with your way just add some more text

configurations {
     all*.exclude group: 'com.android.support', module: 'support-v4'
}

So, now what you have to do is

Search CTRL+SHIFT+N in android studio for the class AuthFailureError.class See which jar contains this and remove it like above (This is just as an example/You have to figure out the duplicate class and manually remove it)

Solution 5:

just remove the duplicate jar file(note:use new version,delete old version) for importing "com.android.volley.AuthFailureError" in build.gradle. Then clean project and rebuild project and then run you will get result.