0

I updated my android studio from 1.5 version to current latest v2.1.1 and also updated build tools version to 2.1.0 and gradle distributionUrl to https://services.gradle.org/distributions/gradle-2.10-all.zip

After updating this changes, I am able to run the application on device but when I try to code sign the application getting this error -

Error:Execution failed for task ':projectName:transformClassesWithJarMergingForRelease'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/android/internal/http/multipart/PartSource.class

Here's look at my build.gradle file -

apply plugin: 'com.android.application'

android {
   signingConfigs {
    config {
        keyAlias 'aliasname'
        keyPassword ''
        storeFile file('/opt/keystorename.keystore')
        storePassword ''
    }
   }
   compileSdkVersion 23
   buildToolsVersion "23.0.3"
   defaultConfig {
    applicationId "com.companyname.project"
    minSdkVersion 9
    targetSdkVersion 23
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    multiDexEnabled true
}
dexOptions{
    incremental true
}

  buildTypes {
    release {
         minifyEnabled false
         proguardFiles getDefaultProguardFile('proguard-android.txt')
         signingConfig signingConfigs.config
         zipAlignEnabled true
     }
 }
}

dependencies {
  compile project(':libraryInfiniteScrollListView')
  compile project(':libraryPagerSlidingTabStrip')
  compile project(':libraryParallaxScroll')
  compile project(':library_CardView_Supportv7')
  compile(project(':librarySwipeListView'))

  compile 'com.google.android.gms:play-services-base:8.4.0'
  compile 'com.google.android.gms:play-services-plus:8.4.0'
  compile 'com.google.android.gms:play-services-location:8.4.0'
  compile 'com.google.android.gms:play-services-gcm:8.4.0'
  compile 'com.android.support:appcompat-v7:23.4.0'
  compile files('libs/AndroidEasingFunctions-1.0.0.jar')
  compile files('libs/AndroidViewAnimations-1.0.6.jar')
  compile files('libs/calligraphy-1.1.0.jar')
  compile files('libs/flexjson-2.1.jar')
  compile files('libs/libBeaconService.jar')
  compile files('libs/libraryhttploopj.jar')
  compile files('libs/localytics.jar')
  compile 'com.nineoldandroids:library:2.4.0'
  compile files('libs/universal-image-loader-1.9.3.jar')
  compile files('libs/YouTubeAndroidPlayerApi.jar')
  compile 'com.android.support:multidex:1.0.1'
  // org.apache.http package is deprecated and removed in 23 sdk version and above
  compile files('libs/org.apache.http.legacy.jar')
}

And My application class is extending MultiDexApplication class instance.

I have even updated my buildToolsVersion to "23.0.3" from "23.0.1" but still getting the same above error.

It will be really helpful if someone can point out what is broken?

Fenil
  • 1,194
  • 10
  • 11
  • Check this answer : http://stackoverflow.com/questions/29872225/java-util-zip-zipexception-duplicate-entry – Renaud Mathieu May 30 '16 at 08:16
  • possible to post complete `build.gradle` file? – PunitD May 30 '16 at 08:19
  • @Droidwala Have edited the post to incorporate complete build..gradle file – Fenil May 30 '16 at 08:54
  • @RenaudMathieu Gone through that link but not helpful – Fenil May 30 '16 at 09:44
  • Try searching for `PartSource.class` in your project..AS might show popup showing the jars in which that class is present..possible source of the error is two different jars in your project are having dependency on two different version of same libraries..are you sure it works when using the debug variant of the app and only gives problem in release variant? – PunitD May 30 '16 at 09:50
  • @Droidwala org.apache.http.legacy.jar file has this class. I have used this jar since, org.apache.http package is deprecated from version 23 – Fenil Jun 01 '16 at 08:49
  • 1
    There might be one more jar in your class using the same `PartSource.class` causing this issue.It maybe `libraryhttploopj` or `universal-image-loader-1.9.3`.Instead of downloading the dependencies from jar (like you do in the project) you could download them from mavenCentral or jcenter() and gradle takes care of avoiding downloading the same transitive dependencies. Like in above case if it finds `apache http lib` downloaded separately then it wouldn't download `apache http lib` as transitive dependency of other lib.Check how gradle handles version conflicts of lib dependencies. – PunitD Jun 01 '16 at 09:20
  • If it is an open-source project feel free to post Github link. – PunitD Jun 01 '16 at 09:21

1 Answers1

0

So it finally turns out that PartSource.class was present in org.apache.http.legacy.jar. And org.apache.http.legacy.jar was added as a dependency in one of the library project and also in project's dependency. It was resolved by commenting out the org.apache.http.legacy.jar dependency in project's gradle.

Still I have no clue as to why it was working on older android studio version and why it is working if i run/debug the app. But still, problem is resolved now

Fenil
  • 1,194
  • 10
  • 11