Error while generating a signed apk in Android Studio - android

I want to generate an apk file out of my project but I keep getting this error while generating the signed apk:
Execution failed for task ':app:transformClassesWithJarMergingForRelease'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelper$PrintHelperStubImpl.class
I'm searching since 6 hours for a solution now and I have tried nearly everything but I can't fix it. Does anyone know how to fix this?
This is my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.pake.lightbulb"
minSdkVersion 14
targetSdkVersion 26
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
sourceSets.main
{
jni.srcDirs=[]
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}
dependencies {
compile('com.google.android.gms:play-services:+')
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
}

Most probably support-v4 library gets also included via the play-services dependency. To exclude it change the relevant dependency line of your gradle to:
compile('com.google.android.gms:play-services:+')
{
exclude module: 'support-v4'
}
To troubleshoot it more and inspect for other duplicates and conflicts, check the dependency tree command of gradle:
gradle -q dependencies --configuration compile

Related

duplicate entry: android/support/v4/graphics/drawable/DrawableCompatHoneycomb.class

After changing minimum sdk to 16 i've got that error
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/graphics/drawable/DrawableCompatHoneycomb.class
this is my build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.nicoleiesperida.crazyjeepney"
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Application.mk'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
compile 'com.facebook.android:facebook-android-sdk:4.+'
}
The same class is being provided by two different dependencies. run
gradle app:dependencies
or
./gradlew app:dependencies
where app is the app project name. Then locate the support v4 package and exclude it from the dependency. Probably it's facebook.

java.util.zip.ZipException: duplicate entry Android

I have been working on a chatting kind of application using xmpp ejabbered. I wanted a signed apk of the app, so i tried getting one but I got the following error. Previously i was getting same error with com.parse library so i removed the library from libs folder and now this error. I searched on net and many people got that error but their libraries are different so I tried implementing that but still wasn't successful.
This is my app level build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "mchat.sunil.com.mchat"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:24.2.1'
compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.0'
compile 'com.parse:parse-android:1.13.1'
compile 'org.jitsi:org.otr4j:0.22'
compile 'com.github.siyamed:android-shape-imageview:0.9.3'
compile 'com.google.code.gson:gson:2.7'
compile 'org.simpleframework:simple-xml:2.7.1'
}
configurations {
all*.exclude group: 'xpp3', module: 'xpp3'
}
The error which i'm getting is
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jxmpp/stringprep/simple/SimpleXmppStringprep.class
Error:Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
Solutions which i tried is excluding it with different libraries one by one.
all*.exclude group: 'jxmpp', module: 'smack-tcp'
all*.exclude group: 'jxmpp', module: 'smack-android-extensions'
all*.exclude group: 'jxmpp', module: 'parse-android'
all*.exclude group: 'jxmpp', module: 'org.otr4j'
but still couldn't find the proper solution. Can anyone help me with this. Any help will be appreciated. Thank you.

Can't add xstream 1.4.8 dependency to Android using gradle

I'm having difficulties with including xstream library to my Android gradle-based app. From what I've read in xstream documentation, it should work "out of the box". However, when I add dependency:
compile 'com.thoughtworks.xstream:xstream:1.4.8'
I get following exception during build process:
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/xmlpull/v1/XmlPullParser.class
Ok, so maybe I should exclude xmlpull? I tried changing this dependency to:
compile ('com.thoughtworks.xstream:xstream:1.4.8') {
exclude group: 'xmlpull', module: 'xmlpull'
}
And, as a result, after some time:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
// ...
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
// ...
1 error; aborting
I've also checked project dependencies using gradle dependencies, but found nothing xml-related there.
My whole build.gradle file:
group 'myGroup'
version '1.0'
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "edu.foo.app"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral();
maven {
url 'https://repository-achartengine.forge.cloudbees.com/snapshot/'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(':Commons')
compile 'commons-io:commons-io:2.4'
compile 'commons-codec:commons-codec:1.10'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'org.achartengine:achartengine:1.2.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.thoughtworks.xstream:xstream:1.4.8'
// compile ('com.thoughtworks.xstream:xstream:1.4.8') {
// exclude group: 'xmlpull', module: 'xmlpull'
// }
}
What should I do to include xstream library to my project?
Solution was to downgrade xstream to v1.4.7 and exclude xmlpull.
compile ('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
I don't know exactly why, but I'd guess that it must be java8-related.
I was getting the same Error.What i did, i just Disable the "Enable all the test artifacts" from my default preferences.
and Open build variants select unit tests..
Hope above Ans may helps any one.

java.util.zip.ZipException: duplicate entry: com/facebook/ads/AbstractAdListener.class

I am trying to implement facebook mobile ads in an android app. Everything went fine but in build gradle i m getting error.
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry:
com/facebook/ads/AbstractAdListener.class.
And build.gradle codes are
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.mohit.warmodroid.practicefbads"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
multiDexEnabled true
}
}
}
dependencies
{
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile ('junit:junit:4.12'){
exclude group: 'com.facebook.ads', module: 'classes.jar'
}
compile 'com.android.support:appcompat-v7:23.0.1'
compile ('com.android.support:design:23.0.1'){
exclude group: 'com.facebook.ads', module: 'classes.jar'
}
compile('com.facebook.android:audience-network-sdk:4.7.0'){
exclude group: 'com.facebook.ads', module: 'classes.jar'
}
compile 'com.android.support:multidex:1.0.0'
}
I tried everything availble on stackoverflow.com but unable to clear it.
Please help me out.
In the Gradle settings and project configurations there is an old version of AudienceNetwork.jar, existing in the \libs folder. Remove this jar file from \libs and rebuild the project: this should fix the problem.

:app:packageAllDebugClassesForMultiDex FAILED, ...zip.ZipException: duplicate entry: android/...v4/widget/SearchViewCompatIcs$MySearchView.class

I've been working on this issues for a several hours but can't find the solution. Tried a lots of answers from stackoverflow but no luck.
What am I getting is the following gradle error while running the app:
:app:packageAllDebugClassesForMultiDex FAILED
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/widget/SearchViewCompatIcs$MySearchView.class
Android studio throws the error when i add the dependency of ShareThis Sdk into the gradle. Here is the full gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'Alies'
keyPassword 'password'
storeFile file('path.jks')
storePassword 'password'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "example.com.app"
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
incremental true
}
//configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
//configurations { all*.exclude module: 'support-v4' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided files('libs/universal-image-loader-1.9.3.jar')
compile project(':library-circular')
compile('com.android.support:appcompat-v7:22.2.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile project(':sliding_library1')
compile('com.google.android.gms:play-services:7.5.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile project(':sdk')
}
A small help will be greatly appreciated.
Seems the problem is in Compile independent modules in parallel (may require larger heap size). So, disabling that option and clear rebuild should fix it.
Looks like Android Build Tools for multidex sometimes try to include lib project in both dex files and it causes some conflict then compiled simultaneously.
So, the problem has been resolved. Actually there was a conflict between support-v4 jar files, So I simply used the same support-v4.jar everywhere and the problem is fixed.

Categories

Resources