Duplicate files copied in APK META-INF - java

hi im new in android development, i am trying to build my apk but i got this erorr. and i update my gradle and i got duplicate copy. how can i fix this error?
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
File1: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp\okhttp\2.0.0\4c8d1536dba3812cc1592090dc20c47a4ed3c35e\okhttp-2.0.0.jar
File2: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.crashlytics.android\crashlytics\1.1.13\e821eafa1bf489a26bdb71f95078c26785b37a1\crashlytics-1.1.13.jar
and here's my build.gradle is this the error comes?
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.mymonas.ngobrol"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "0.9.0.68"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'], exclude: 'android-support-v4.jar')
compile project('libs:floatlabel')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.1'
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.andreabaccega:android-form-edittext:1.1.0#aar'
compile 'com.crashlytics.android:crashlytics:1.+'
}

I had the same or at least a very similar problem today with our React Native app. The problem was only on my Mac though. The only plausible explanation we could think of was that I updated a bunch of Android Studio tools and then gradle couldn't build properly with our dependencies. Anyways after excluding the pom.properties and pom.xml from okhttp I kept getting the same error but it turns out that I just had to exclude even more files. This is my complete packagingOptions in build.gradle:
packagingOptions {
exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}

to solve your problem please add this to your build gradle
packagingOptions {
exclude 'META-INF/pom.properties' /*OR*/ 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
}

It seems like okhttp and crashlytics don't work together in newer gradle versions (2.10 in my case). I fixed this by updating the crashlytics to a newer version (which is now called Fabric).

packagingOptions
{
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
}
Please check for correct path "com.squareup.okhttp/okhttp/pom.properties" in your errorlog.

Related

Gradle - Couldn't expand zip cardview-v7-23.3.0.aar

I try to implement firebase into my app. But there is an interference between firebase and google play service.
Here is my build.gradle for the module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.nefrin.client"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.github.tajchert:nammu:1.1.3'
compile 'gun0912.ted:tedpermission:1.0.3'
compile 'com.github.jksiezni.permissive:permissive:0.2'
compile 'com.github.arimorty:floatingsearchview:2.0.3'
//compile 'net.sf.sprockets:sprockets-android:4.0.0'
compile 'com.github.michael-rapp:android-material-dialog:4.0.2'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.google.firebase:firebase-auth:11.2.0'
}
apply plugin: 'com.google.gms.google-services'
And here is build.gradle for the project:
// 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:2.1.2'
classpath 'com.google.gms:google-services:3.1.0' // google-services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When I try to run the app I get eventhough I didn't use cardview in my app:
Error:Execution failed for task ':app:prepareComAndroidSupportCardviewV72330Library'.
> Could not expand ZIP 'C:\Users\Nefrin\.gradle\caches\modules-2\files-2.1\com.android.support\cardview-v7\23.3.0\abdf83a0192c03ff190f941c6c885af18d257a2c\cardview-v7-23.3.0.aar'.
Android Studio is underlining the compile 'com.google.android.gms:play-services:11.0.4' and says:
All com.google.android.gms libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 11.2.0, 11.0.4. Examples include com.google.android.gms:play-services-basement:11.2.0 and com.google.android.gms:play-services:11.0.4 less... (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)
As the error says all the google libraries should use the same version.
So you should update the play-services library and use the same version as firebase:
compile 'com.google.android.gms:play-services:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
You need to change this line of code:
compile 'com.google.android.gms:play-services:11.0.4'
with
compile 'com.google.android.gms:play-services:11.2.0'
Hope it helps.

duplicate entry: com/google/android/gms/internal/zzqv.class Android Studio

In my project i have implemented play-services-games,first I have tried to add
compile 'com.google.android.gms:play-services:10.0.1'
but i got into some troubles and the solutions that i found was to compile only the needed library
compile 'com.google.android.gms:play-services-games:10.0.1'
and all was great but when I've tried to add play-services-ads things got messy,I have added
compile 'com.google.android.gms:play-services-ads:10.0.1'
Now i get
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqv.class
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.apps.fightersam"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile name: 'unity-ads', ext: 'aar'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.google.android.gms:play-services-games:10.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile project(':BaseGameUtils')
}
repositories {
flatDir {
dirs 'libs'
}
}
You have to exclude the duplicate use of an internal transitive dependency.
To find out which
gradle -q dependencies
This will give you the dependency tree. Then you can do something like
compile('com.example.m:m:1.0') {
exclude group: 'org.unwanted', module: 'x
}
I was using the latest version of FirebaseUI 2.0.0 which seemed to be incompatible with google-services:3.0.0. Therefore I downgraded FirebaseUI version to 1.2.0 and added the following code to Project level build.gradle:
allprojects {
repositories {
jcenter()
// Add the following
maven {
url 'https://maven.fabric.io/public'
}
}
}
I had a problem like this, but in my case I have two versions of the Google libraries being imported. In your case
delete this from your dependencies:
compile 'com.google.android.gms:play-services-ads:10.0.1'
Because it's imported from:
compile name: 'unity-ads', ext: 'aar'
Or do the opposite delet unity-ads and let compile 'com.google.android.gms:play-services-ads:10.0.1'
goodluck
In my case Downgrading Both 'com.google.android.gms:play-services-games:10.0.1' and 'com.google.android.gms:play-services-ads:10.0.1'
To 'com.google.android.gms:play-services-games:9.0.1' and 'com.google.android.gms:play-services-ads:9.0.1' did the trick !

Duplicate entry in build.gradle zznp.class

I am trying to implement Applozic chat in my existing android app. I am already using MQTT for server communication in other classes and its working fine. But after downloading the Applozic library through build.gradle I am getting an error while compiling the application. Applozic also seems to be using the same MQTT technology. The error says:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zznp.class
:app:transformClassesWithJarMergingForDebug FAILED
The build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.xxxxx.xxxx.xxx"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
// Enabling multidex support.
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'
exclude 'META-INF/ECLIPSE_.SF'
exclude 'META-INF/ECLIPSE_.RSA'
}
}
/*allprojects {
repositories {
jcenter()
maven {
url "https://repo.eclipse.org/content/repositories/paho-releases/"
}
maven { url "https://jitpack.io" }
}
}*/
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
//testCompile 'junit:junit:4.12'
compile 'com.applozic.communication.uiwidget:mobicomkitui:4.62'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'com.android.volley:volley:1.0.+'
compile 'com.vlonjatg.android:app-tour:1.0'
compile 'com.mukesh:permissions:1.0.2'
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
/*compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
compile(project(':org.eclipse.paho.android.service')) {
transitive = true
}*/
}
task publishAPK(type: Copy) {
from file("${project.buildDir}/outputs/apk/" + rootProject.ext.sampleArchivesBaseName + "-debug.apk");
into '/shared/technology/paho/Android/' + rootProject.ext.sampleVersion + '/debug/';
}
configurations.compile.exclude module: 'org.eclipse.paho.client.mqttv3'
task debug << {
configurations.compile.each { println it}
}
I do not understand why the error shows up. Which library is causing the conflict? What do I need to modify in order to remove the issue?
The error is due to this compile 'com.google.android.gms:play-services:7.8.0'
lib as it is shown in the
error duplicate entry: com/google/android/gms/internal/zznp.class
:app:transformClassesWithJarMergingForDebug FAILED
try to remove this and sync the project .hope it work
Applozic android sdk is using Google play services v9.0.2 can you check by changing to v9.0.2
compile 'com.google.android.gms:play-services:9.0.2'
and if it exceeds 65k check this link
How to enable multidexing with the new Android Multidex support library

java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class

I have seen similar responses to the below question. Sorry but i could not fixed it out trying multiple things so I am asking it again.
Whenever I am trying to build my app, the gradle build throws me the below error stating ...due to duplicate entry of javax/Inject class.
This only occurred when I am trying to put compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.9' in my build.gradle file; This package is necessary for javax.ws.rs.* services.
I tried running the gradlew clean command in my root directory, it says that build is successful but when I am building my application again it started throwing the error again.
Can you please help on the below error:
*Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class*
Below is my app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.usfca.studentrecordsverifycation"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://maven.restlet.com' }
maven { url 'https://maven.java.net/content/repositories/releases/' }
maven { url 'http://download.java.net/maven/2/' }
maven { url 'http://download.java.net/maven/1' }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'log4j:log4j:1.2.17'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.madgag:sc-light-jdk15on:1.47.0.3'
compile 'com.cloudinary:cloudinary-http44:1.4.5'
compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.9'
compile 'commons-lang:commons-lang:2.6'
}
Below is my Project gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Ok so I created a sample project with all those dependencies and I got a different error.
So if you are still getting the ZipException error, you have some jars in your lib folder that we are not aware of?
Here's the error I got:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
If you are getting a similar error, all you need to do is add the following to your build.gradle:
android {
defaultConfig {
...
}
buildTypes {
....
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
If this doesn't make any difference, do you have any jar libraries in your project? If so, we need to see the list.
EDIT:
I can't know for sure if it will work because I am not getting the same error. In your dependencies, change to this:
compile ('org.glassfish.jersey.containers:jersey-container-jdk-http:2.9') {
exclude group: 'javax.inject', module: 'javax.inject'
}
This error means that the class javax.inject.Inject is being included twice in your apk when the dexer runs. That is, this exact same class is coming from 2 different dependencies. One of them is probably org.glassfish.jersey.containers:jersey-container-jdk-http:2.9 because it happens after you added it.
If you CMD+O (jump to class) on Android Studio, you should be able to see the 2 versions of this class and see where they are coming from. Make sure you select the checkbox that allows it to show classes included from your dependencies. Once you open them, hover over the file tab and you'll see a tooltip with the artifact name. That is gonna be the dependency that's including that class.
Hope it makes sense.

Android Release Build

I was facing a problem earlier this week. When I tried to do the Android release build it seemed to show the following error --
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzjm.class
I was wondering how I got this error and how to fix it. It seems as if the problem was inside the build.gradle files. Here they are --
App Level -
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.unknown.app"
minSdkVersion 13
targetSdkVersion 23
versionCode 20
versionName "2.34"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':BaseGameUtils')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.firebase:firebase-ads:9.0.2'
compile ('com.google.android.gms:play-services:9.0.2'){
exclude group: 'com.google.android.gms.play-services-ads'
}
compile project(path: ':BaseGameUtils')
}
apply plugin: 'com.google.gms.google-services'
Here is the top level --
// 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:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Thanks for all help. I have been having this issue for a little while. I could not find the answer in any other stack overflow questions. Thanks Again.
the error explains itself, it means that it found two libraries which are the same
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-identity:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
by including com.google.android.gms:play-services:9.0.2 you are actually including all the play-service libraries, please remove it and you should be fine or remove the others "below it".
you are including the
'com.google.firebase:firebase-ads:9.0.2'
and
'com.google.android.gms:play-services-ads:9.0.2'
but firebase already includes the second library so you don't have to include this one just use the ads library from firebase
It seems as if the BaseGameUtils module was causing the problem. I am not sure why but reomving it, and replacing the BaseGameUtils for some reason did the trick, and the error did not show anymore. Thanks for all the help along the way of figuring out the issue.

Categories