android - java.util.zip.ZipException: duplicate entry :how to overcome -


i have used multiple android libraries , modules in project. each 1 has own v4.support lib. getting java.util.zip.zipexception: duplicate entry . when search duplicate class file in project, there multiple files of these classes because of multiple v4.support lib in each libraries. know question has been asked many times here nothing working me .

my question : how remove these multiple v4.support files ? want put v4.support lib once , other module should reference there. how achieve this?

following build.gradle script

// top-level build file can add configuration options common sub-projects/modules. buildscript {     repositories {         mavencentral()         maven { url 'https://maven.fabric.io/public' }     }     dependencies {         classpath 'com.android.tools.build:gradle:1.1.0'         classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'         //classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'         classpath 'io.fabric.tools:gradle:1.15.2'     } }  apply plugin: 'android' apply plugin: 'com.android.application' apply plugin: 'android-apt' apply plugin: 'io.fabric'  repositories {     maven { url 'https://maven.fabric.io/public' } }  dependencies {     compile filetree(dir: 'libs', include: '*.jar')     compile('com.crashlytics.sdk.android:crashlytics:2.2.3@aar') {         transitive = true     }     compile('com.android.support:multidex:1.0.0')     //compile ('com.android.support:appcompat-v7:22.1.0')     compile project(':..:..:..:..:..:..:android_libraries:appcompat')     compile project(':..:..:..:..:..:..:android_libraries:facebook')     compile project(':..:..:..:..:..:..:android_libraries:google_play_services:libproject:google-play-services_lib')     compile project(':..:..:..:..:..:..:android_libraries:slidingmenu')     compile project(':..:..:..:..:..:..:android_libraries:stickinggridviewlibrary')     compile project(':..:..:..:..:..:..:android_libraries:view_pager_library')     compile project(':..:..:..:..:..:..:android_libraries:zxing2.3')     compile project(':..:..:..:..:..:..:android_libraries:xyz')     compile project(':..:..:..:..:..:..:android_libraries:apptentive')  }  android {     compilesdkversion 21     buildtoolsversion "21.1.0"      defaultconfig {         versioncode 1         versionname "1.0"         minsdkversion 15         targetsdkversion 21          // enabling multidex support.         multidexenabled true     }      compileoptions {         sourcecompatibility javaversion.version_1_7         targetcompatibility javaversion.version_1_7     }      ant.importbuild './../../../../../../buildscripts/wlbuild.xml'       apt {         arguments {             androidmanifestfile variant.outputs[0].processresources.manifestfile             // if have multiple outputs (when using splits), may want have other index 0              resourcepackagename 'com.kohls.mcommerce.opal'              // if you're using android nbs flavors should use following line instead of hard-coded packagename             // resourcepackagename android.defaultconfig.applicationid              // can set optional annotation processing options here, these commented options:             // loglevel 'info'             // logfile '/var/log/aa.log'         }     }     sourcesets {         main {             manifest.srcfile 'androidmanifest.xml'             java.srcdirs = ['src']             resources.srcdirs = ['src']             aidl.srcdirs = ['src']             renderscript.srcdirs = ['src']             res.srcdirs = ['res']             assets.srcdirs = ['assets']         }          // move tests tests/java, tests/res, etc...         instrumenttest.setroot('tests')          // move build types build-types/<type>         // instance, build-types/debug/java, build-types/debug/androidmanifest.xml, ...         // moves them out of them default location under src/<type>/...         // conflict src/ being used main source set.         // adding new build types or product flavors should accompanied         // similar customization.         debug.setroot('build-types/debug')         release.setroot('build-types/release')     }     builddir = './../../../../../../build/native'      lintoptions {         abortonerror false     }     dexoptions {         incremental true         javamaxheapsize "4g"     }     packagingoptions {         exclude 'meta-inf/license.txt'     } } 

and getting errors this. each time clean project complies successfully. when try give run command shows following types of error.

execution failed task ':packagealldebugclassesformultidex'. > java.util.zip.zipexception: duplicate entry: android/support/v4/media/transportmediatorcallback.class 

as workaround above problem , find way overcome it. main reason packagealldebugclassesformultidex error same find in other posts in stackoverflow i.e. must have class files available more once in project. in case have many modules in above project facebook , google pay services , sliding menu etc.. . these module have there own copy of v4.support jar file. did delete v4.support files these libraries libs folder. add dependency v4.support lib sdks i.e. com.android.support libs android studio project structure. this..

  • 1* go file>project structure.
  • 2* select each 1 of these modules 1 one.

  • 3* in last tab named dependency , remove compile filetree(dir: 'libs', include: '*.jar') if had v4.support lib (or probleomatic one)in libs folder of module.

  • 4* add v4.support lib clicking + add libraries , select v4.support libs sdks.

its done. clean project , build again.packagealldebugclassesformultidex problem has gone.

as transitive dependency , if know exact dependency cause duplicate file in dex error while building project, can exclude belo

 compile(project(':..:..:..:..:..:..:android_libraries:walletsdkandroidmodule')) {         exclude group: 'com.google.code.gson'     } 

if want transitive dependency in module, eg.

compile('com.crashlytics.sdk.android:crashlytics:2.2.3@aar') {         transitive = true     } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -