1

I am trying to import eclipse project into android studio.After that adding my jar file i.e support jar into build gradle file whatever I have used in eclipse. While doing that getting below error.

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class

and my build gradle file is:

apply plugin: 'com.android.application'
configurations {
   // all*.exclude group: 'com.android.support', module: 'support-v4'
   // all*.exclude group: 'com.android.support', module: 'support-annotations'
}
android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"

    useLibrary  'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.xxx.xxxxx"
        minSdkVersion 19
        targetSdkVersion 25
        multiDexEnabled true
    }

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

    aaptOptions {
        cruncherEnabled = false
    }

}

dependencies {
    //compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/android-query-full.0.26.7.jar')
    compile files('libs/commons-httpclient-3.0.1.jar')
    compile files('libs/glide-3.6.1.jar')
    compile files('libs/httpmime-4.1.3.jar')
    compile files('libs/library-1.2.1.jar')
    compile files('libs/mpandroidchartlibrary-2-2-4.jar')
    compile files('libs/picasso-2.4.0.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/android-support-v7-appcompat.jar')
   compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
        exclude module: 'support-v4' // exclude duplicate library
    }

}
UltimateDevil
  • 2,807
  • 2
  • 18
  • 31
DurgaPrasad Ganti
  • 1,008
  • 4
  • 20
  • 41

3 Answers3

4

java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class

Problem

  • exclude module: 'support-v4'

Don't

compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
    exclude module: 'support-v4' // exclude duplicate library
}

You Should Use

compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.android.service', version: '1.0.2'

If problem coming then add this in your build.gradle section

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }

Then Clean-Rebuild-Run .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Put below code below buildTypes and rebuild again project

    packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file
    exclude 'META-INF/DEPENDENCIES' // will not include LICENSE file
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
UltimateDevil
  • 2,807
  • 2
  • 18
  • 31
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57
0

Remove the line

compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
    exclude module: 'support-v4' // exclude duplicate library
} 

and add this line

compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile org.eclipse.paho:org.eclipse.paho.android.service:1.0.2

Also add this inside the android{ }

repositories {
    mavenCentral()
}

For more information check this link https://www.eclipse.org/paho/clients/android/

Sharath kumar
  • 4,064
  • 1
  • 14
  • 20