7

I have been battling this error all day in Android Studio. Project was imported from an eclipse solution. I have been trying to implement all fixes that are listed for similar posts, nothing is working. I am an Android beginner.

I will be happy to provide any further information.

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

java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

Please help!! Should I just try to get it to run in Eclipse?

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.appname.android"
        minSdkVersion 8
        targetSdkVersion 18
        multiDexEnabled true
    }

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

dependencies {
    compile 'com.android.support:support-v4:22.1.1'
    compile files('libs/ksoap2-android-assembly-3.1.0-jar-with-dependencies.jar')
    provided files('libs/zxing-core.jar')
}
user2512589
  • 103
  • 1
  • 1
  • 6

2 Answers2

7

Make sure you have the latest build toolds and sdk from the SDK manager. I have converted those jars to Gradle dependencies.

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' } // <-- added for ksoap
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3' // <-- updated
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' } // <-- added for ksoap
    }
}

app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1" // <-- updated

    defaultConfig {
        applicationId "com.appname.android"
        minSdkVersion 8
        targetSdkVersion 22  // <-- updated
        // multiDexEnabled true  // <-- you do not need this
    }

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

dependencies {
    compile 'com.android.support:support-v4:22.1.1'
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.4.0'
    // compile files('libs/ksoap2-android-assembly-3.1.0-jar-with-dependencies.jar') // <-- avoid using jars
    compile 'com.google.zxing:core:3.2.0'
    // provided files('libs/zxing-core.jar') // <-- avoid using jars
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • Feel like it is close. Got the following: Error:(23, 13) Failed to resolve: com.google.code.ksoap2-android:ksoap2-android:3.4.0 – user2512589 Apr 26 '15 at 17:36
  • Did you not add `maven { url 'http://ksoap2-android.googlecode.com/svn/m2-repo' }`? – Jared Burrows Apr 26 '15 at 17:37
  • Yes, I copied the build.gradle you provided. Android Studio made me install SDK 22 as well. – user2512589 Apr 26 '15 at 17:48
  • Thanks! it is now compiling with your changes. It is still a blank emulator? Maybe something with the Emulator settings? Maybe my development machine isn't powerful enough? – user2512589 Apr 26 '15 at 18:19
  • I got it compiling at least! Are their errors in `ADB`? What is in `MainActivity`? Since I answered this one, could you make another question? – Jared Burrows Apr 26 '15 at 18:21
  • Yes, you did! One step closer! Thank you!! I created new post at: http://stackoverflow.com/questions/29881721/blank-emulator-in-android-studio – user2512589 Apr 26 '15 at 18:30
  • 1
    Replacing `compile files('libs/zxing-core.jar')` with the Maven repository version `compile 'com.google.zxing:core:3.2.0'` did the trick for me. Using Maven allows it to resolve version dependencies instead of creating duplicates. Thanks, big time! – Joshua Pinter Mar 01 '17 at 14:40
2

java.util.zip.ZipException: duplicate entry

I am also facing with the same issue.But I was resolved.

This problem occurs mainly when we move the project one system to another system. so one system gradle versions and SDK tools version are different to other system.

please check if you import the project from another system or downloaded from the internet

1.gradle versions of your system and downloaded application are matched are not?

  1. and SDK tools are matched are not?

If The project in the same system, but you get the Same exception, then the above solution may be helpful.

My problem is Application "dependencies" are lower versions than the System sdk tools version.

we should provide the correct version for each dependencies of your Application, regarding to your system SDK tools version.

I think Android studio may be confusing us. That exception is should be a mismatching the System SDK tools versions with Application dependencies versions.

In my Application one of the dependency is "support-v7" version is 24.1.1 but my system having the "support-v7:24.2.0". so I was changed to latest version. then my problem was solved.

Kona Suresh
  • 1,836
  • 1
  • 15
  • 25