问题
I'm trying to add a library to my project, right now my current build.gradle
is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
repositories {
mavenCentral()
}
defaultConfig {
applicationId "com.example.guycohen.cheaters"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.whl.handytabbar:library:1.0.4'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
}
When I add a new library
compile 'com.github.navasmdc:PhoneTutorial:1.+@aar'
I get this error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$2$1.class
I've tried to fix this issue by adding
configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
I couldn't find a duplicate class in my project.
I'm sure whether if I could delete the duplicate entry it would run perfectly, but I'm not sure how I'd find it.
回答1:
compile 'com.android.support:support-v4:22.1.1'
compile ('com.android.support:appcompat-v7:22.1.1') {
exclude module: 'support-v4'
}
compile ('com.facebook.android:facebook-android-sdk:4.2.0') {
exclude module: 'support-v4'
}
compile ('com.github.navasmdc:PhoneTutorial:1.+@aar') {
exclude module: 'support-v4'
}
回答2:
I use this to replace all support libraries versions with the latest one that i use in gradle file:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion "26.0.1"
}
}
}
}
回答3:
Try using this versions in build.gradle file.
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
回答4:
Your Error:
java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$2$1.class
Step 1: In this case main hint is android/support/v4/print/PrintHelperKitkat$2$1.class
Step 2: Searching for the class, in your case the "PrintHelperKitkat.class" (in AndroidStudio just hit Ctrl+N on Windows or CMD-O on Mac)
Step 3: See which jar contains it - Android Studio will write it in the popup.
Step 4: Exclude it from all builds,
for example:
com.android.support:support-v4:_____
compile('your_conflicted_dependency')
{
exclude module: 'support-v4'
}
In my case my one dependency also included in my another AAR. So I deleted that dependency
回答5:
I was faced the same issue. I solved it by,
Make sure that in all imported project's build.gradle
file should have same compileSdkVersion
and dependencies
versions like in your project's build.gradle
file.
It will remove this error.
来源:https://stackoverflow.com/questions/30769483/error-java-util-zip-zipexception-duplicate-entry