0

I can run my application on devices using USB, But when i tried to build APK it's measure this error :

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/HttpHeaders.class

my gradle :

apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 25 buildToolsVersion "25.0.2" useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "elryad.harajsooq" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled = true } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.2.3' compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5' // compile 'org.apache.httpcomponents:httpcore:4.4.1' // compile 'org.apache.httpcomponents:httpclient:4.5' // compile 'org.apache.httpcomponents:httpmime:4.2.3' compile files('libs/volley.jar') compile 'com.android.support:appcompat-v7:25.3.0' compile 'com.android.support:design:25.3.0' compile 'com.android.support:support-annotations:25.3.0' compile 'de.hdodenhof:circleimageview:1.3.0' compile 'com.mcxiaoke.volley:library-aar:1.0.0' compile 'com.android.support:palette-v7:25.3.0' compile 'com.android.support:recyclerview-v7:25.3.0' compile 'com.android.support:cardview-v7:25.3.0' compile 'com.squareup.okhttp3:okhttp:3.1.2' //compile 'com.android.support:support-v7:25.0.2' compile "com.android.support:support-core-utils:25.3.0" compile 'com.android.support:support-v13:25.3.0' compile 'com.google.code.gson:gson:2.7' compile 'com.google.firebase:firebase-messaging:9.0.0' compile 'com.google.android.gms:play-services:9.0.0' compile 'com.android.support.constraint:constraint-layout:1.0.1' compile 'com.squareup.picasso:picasso:2.5.2' testCompile 'junit:junit:4.12' compile 'com.android.support:multidex:1.0.1' } 

1 Answer 1

2

Legacy Apache HTTP

You're bundling a version of Apache HTTP with your app. Remove this line from all modules' build.gradle:

useLibrary 'org.apache.http.legacy' 

Behind the scenes that method actually includes a JAR of an old version of Apache HTTP which is not what you want if you're managing dependencies through Gradle/maven.

Matching versions

All imported artifacts from Apache HTTP have to have the same version.

compile 'org.apache.httpcomponents:httpmime:4.5.3' compile 'org.apache.httpcomponents:httpclient-android:4.5.3' 

Well, httpcore does not follow this sheme, then again consider it an internal transitive dependency, appropriate version is pulled automatically by whatever version of httpclient you use. You don't have to specify it manually.

List of Apache HTTP artifacts in maven: https://mvnrepository.com/artifact/org.apache.httpcomponents

Sign up to request clarification or add additional context in comments.

2 Comments

i used 'org.apache.http.legacy' in many places in my application.. it there any way instead ? and after i matched the version of apache.http it's throw another error : Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/android/volley/AuthFailureError.class btw why i can install the app but i can't build apk ?
You're installing the old apk. Don't import Volley JAR you already import it thorugh maven. In fact you can probably import everything using maven instread of JAR. For more control remove compile fileTree(dir: 'libs', include: ['*.jar']) as well.