How to solve a Duplicate file exception in android? - android

I am trying to make a chat application using Firebase. The code seems to be fine but I am getting a strange error while trying to run the project.
Here is the error:
Error:FAILURE: Build failed with an exception.
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
File1: C:\Users\Aadesh\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.2.2\285cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar
File2: C:\Users\Aadesh\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.2.2\3c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
File3: C:\Users\Aadesh\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
What could be the problem and how do i solve this?
Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.aadesh.chatnow"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.volley:volley:1.0.0'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.5.2'
}
apply plugin: 'com.google.gms.google-services'

You should add:
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
to your build.gradle file. this will skip those files while merging libs.

Related

How to import org.springframework.data into Android Studio using Gradle

I need the org.springframework.data.geo.Point class in my Spring Android app. I have the spring-android dependency already downloaded here. This does not have the .data section. When I try to use Gradle to import a different library I get duplication file errors. After consulting this link I get errors involving Dex cannot parse version 52 byte code. While reviewing this previous post I read that this wasn't the recommend way of getting rid of these errors.
Is there a spring library that I can import that has the org.springframework.data as well as everything given in the org.springframework.android:spring-android-rest-template:2.0.0.M3 library.
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.avi.myapplication"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
//pickFirst 'META-INF/spring.schemas'
//pickFirst 'META-INF/spring.tooling'
//pickFirst 'META-INF/spring.handlers'
//pickFirst 'META-INF/spring.factories'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
}
repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
Error Message after following this:
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/spring.schemas
File1: C:\Users\Avi.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-commons\2.0.2.RELEASE\1befa3239976b856202b1735531910a0c2f4e17f\spring-data-commons-2.0.2.RELEASE.jar
File2: C:\Users\Avi.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.0.2.RELEASE\301ee07b390bc8b5691f4206411b49beb06f7ff2\spring-beans-5.0.2.RELEASE.jar
Error Message after following this:
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

error while using firebase

When i'm using Firebase I always face this error !
Error:FAILURE: Build failed with an exception.
What went wrong:
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
File1: C:\Users\e171x.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar
File2: C:\Users\e171x.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.2.2\3c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
File3: C:\Users\e171x.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.2.2\285cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar
Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
which doesn't allow the emulator to run
my app gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.e171x.testingonline"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-crash:9.8.0'
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.firebase:firebase-client-android:2.3.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
It looks like you are adding one of the JARs, namely jackson-core-2.2.2.jar from multiple modules. If you are using Android Studio, check in build.gradle files of each of your modules to check where the duplication is. You may keep it where it is accessible from all modules based on your dependency chain.
Replace:
compile 'com.firebase:firebase-client-android:2.3.1'
with:
compile('com.firebase:firebase-client-android:2.3.1', {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-bind'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
})
You should not use both the legacy Firebase SDK, com.firebase:firebase-client-android:2.3.1, and the libraries of the new 9.x.x SDK in the same app. They are not compatible and will interfere with each other. Remove com.firebase:firebase-client-android:2.3.1 and read the Firebase Upgrade Guide for tips on code changes.

Updated Android Studio, receiving DuplicateFileException

I just updated Android Studio and I cannot build my app after doing so. I receive an exception looking like this:
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/LICENSE
File1: /Users/andersvincentlund/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.2/d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b/jackson-core-2.2.2.jar
File2: /Users/andersvincentlund/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.2.2/3c8f6018eaa72d43b261181e801e6f8676c16ef6/jackson-databind-2.2.2.jar
File3: /Users/andersvincentlund/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.2.2/285cb9c666f0f0f3dd8a1be04e1f457eb7b15113/jackson-annotations-2.2.2.jar
I have googled this type of error and have been suggested to add:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude '...'
}
in the android clause in gradle. This changes nothing(except makes my build potentially illegal since I would be ignoring licensing for OS code?). Does anyone have an idea on how to solve this? I was hoping an update would not break the code.
EDIT:
I got a comment regarding gradle file so I am posting the entire thing below:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
signingConfigs {
config {
keyPassword 'XXXXX'
storeFile file('/XXXXX/XXXXX/XXXXX/android.keystore')
storePassword 'XXXXX'
keyAlias 'XXXXX'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "XXXXX"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.config
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
apt 'com.google.dagger:dagger-compiler:2.5'
provided 'javax.annotation:jsr250-api:1.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.dagger:dagger:2.5'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.firebaseui:firebase-ui:0.3.1'
compile 'com.firebase:firebase-client-android:2.4.0'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
}
apply plugin: 'com.google.gms.google-services'
Just Remove:
compile fileTree(include: ['*.jar'], dir: 'libs')
from
dependencies {}
The jackson-core-2.2.2.jaris already present in your libs/ but another dependency is trying to add it again externally.
Please add below line
packagingOptions {
exclude 'META-INF/maven/com.belerweb/pinyin4j/pom.xml'
exclude 'META-INF/maven/com.belerweb/pinyin4j/pom.properties'}

Error during Building an APK file in Android Studio 2.1.1

Couple of days ago, I upgraded my Android Studio, and now I am facing a problem.
Actually I am trying to build an APK file from my project to test my app on a real device and when I click at Build--> Build Apk then I receive couple of errors in Message Gradle Build. I don't know why these errors are coming please elaborate on the reason as well.
Errors
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/android/volley/VolleyError;
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2
build.gradle file
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.dovezeal.gapp"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
//compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.1.1'
// Volley
compile 'com.android.volley:volley:1.0.0'
//compile 'com.mcxiaoke.volley:library:1.0.+'
/* compile files('libs/com.mcxiaoke.volley library-1.0.0.jar')*/
// RecyclerView
compile 'com.android.support:recyclerview-v7:23.0.+'
// A simple way to define and render UI specs on top of your Android UI.
compile 'org.lucasr.dspec:dspec:0.1.1'
compile files('libs/library-1.0.0.jar')
// YouTube Player
compile files('libs/YouTubeAndroidPlayerApi.jar')
// GOSN
/* compile files('libs/gson-2.2.3.jar')*/
}
Edit - 1
As janki gadhiya said in her comment below, to change minifyEnabled true and try adding multiDexEnabled true under defaultConfig
with these changes both errors above are gone, but now this following error is coming up.
Error:Execution failed for task:app:transformClassesWithJarMergingForDebug'
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/android/volley/Request$Priority.class
build.gradle file
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.dovezeal.gapp"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
//compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.1.1'
// as you already compiled gradle for volley here
compile 'com.android.volley:volley:1.0.0'
// RecyclerView
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'org.lucasr.dspec:dspec:0.1.1'
// you don't need this so comment the below line.
//compile files('libs/library-1.0.0.jar')
// YouTube Player
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
Edit : Explanations
Your errors 1 - 2 : mean you are having more than 65,000 methods in your project, so I told you to set multiDexEnable true.
Your error 3 : means you're having more than one library having the implementation for the class Request$Priority.class, so the compiler is confused which to choose. So it is showing the error Duplicate entry. This will be solved by packaging options, this will let you use duplicate files.
Add this in your build gradle
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
I am also getting the same error. When adding the
compile 'com.google.firebase:firebase-ads:10.2.0'
but it is removed when i do as follow:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.firebase:firebase-ads:10.2.0'
}
apply plugin: 'com.google.gms.google-services'**
and in BuildVarient use debugging mode.
I think it will help you.
while updating firebase any google play services then try to update all the libraries. this worked for me. hope it works in some cases.
Bit late to answer but I faced the same issue.
I was able to rectify it using multiDexEnabled -> true
and used packaging options in build.gradle, post the changes .apk got installed successfully.
Syntax:
defaultConfig {
....
....
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
buildTypes {
...
...
}
Hope it helps.

Android Studio - ':app:packageAllDebugClassesForMultiDex' Duplicate entry android support v4

I get the error
"Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: android/support/v4/content/ContextCompatKitKat.class"
I am using apache jars for httpclient and android-support-v4.jar.
I am really new to this and am not sure why i am getting this error.
my build.gradle looks this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
defaultConfig {
applicationId "com.example.petersenrr.test"
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
//compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile files('libs/android-support-v4.jar')
compile files('libs/httpclient-android-4.3.5.jar')
compile files('libs/httpclient-4.5.2.jar')
compile files('libs/httpcore-4.4.4.jar')
}
During gradle sync it is fine, just when i try to run it do i get this error.
Any help is appreciated
Thanks

Categories

Resources