error while using firebase - android

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.

Related

How to solve a Duplicate file exception in 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.

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.

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' while using YouTube API

I'm using the YouTube SDK to play videos in a viewpager. As soon as I run the app, this error is thrown:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/youtube/player/internal/u.class
Manifest.xml:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.xxxxx.www.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
mavenLocal()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.thefinestartist:ytpa:1.2.1'
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
compile 'com.mxn.soul:flowingdrawer-core:1.2.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3'
compile('com.github.afollestad.material-dialogs:core:0.8.5.7#aar') {
transitive = true
}
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
}
I can't include
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
as viewpager uses support library v4
That error comes when any of your jar dependency have same class. Make sure you have not added support jar both as gradle and jar dependency. There might be duplicate references to the same API.
Try ./gradlew yourBuildVariantName --debug from the command line. You can safely remove it from the project or from your build file(s), clean using the command ./gradlew clean and rebuild the project(repeat if necessary).
Check this related SO questions Gradle Duplicate Entry: java.util.zip.ZipException and java.util.zip.ZipException: duplicate entry during packageAllDebugClassesForMultiDex.
I observed the same issue after Android Studio upgrade to version 2.2 Preview 6
Then I deleted lines:
compile(name: 'YouTubeAndroidPlayerApi', ext: 'jar')
and
flatDir { dirs 'libs'}
from two build.gradle files and the issue is gone.
Looks like 'libs' directory is built automatically now but I'm not able to find any confirmation on Google pages.
Add
dependencies {
compile 'com.android.support:support-v4:24.2.1'
}
in build.gradle file.

Duplicate entry using Parse and Multidex

My project is a Chat app that uses Parse. After added other dependencies, this problem started appearing:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 2
Searching here in StackOverflow, some folks told me that it could be the 65K limit from Android.
So, to solve I followed the steps below:
1 - Add Multidex
DefaultConfig {
         multiDexEnabled true
}
and
compile 'com.android.support:multidex:1.0.0'
https://developer.android.com/tools/building/multidex.html
2 - Enable Jumbo Mode in Android Gradle Settings
dexOptions {
jumboMode = true
}
I cleaned the project and ran the gradle build. It did not generate any errors. Great! But when I click "Run app" it generates this error below.
Error: Execution failed for task ': app:
packageAllDebugClassesForMultiDex'. > Java.util.zip.ZipException:
duplicate entry: bolts / AggregateException.class
If I remove the dependency 'com.parse.bolts: bolts-android: 1. +' the "Run app" works, but I can not do without the dependency of Parse.
This is my Gradle build script:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "br.com.triangulum.mink"
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode = true
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile('com.android.support:multidex:1.0.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: 'Parse*.jar')
compile project('libraries:httprequest')
compile project('libraries:cameralibrary')
compile project('libraries:bgarefreshlayout')
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:palette-v7:+'
compile 'com.android.support:design:+'
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.afollestad:material-dialogs:0.7.4.0'
compile 'com.getbase:floatingactionbutton:1.10.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'de.greenrobot:eventbus:2.4.+'
compile'com.edmodo:cropper:1.0.+'
compile 'com.github.ksoichiro:android-observablescrollview:+'
compile 'com.etsy.android.grid:library:1.0.5'
compile('com.mikepenz:actionitembadge:3.0.2#aar') {
transitive = true
}
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'com.android.support:multidex:1.0.+'
}
try to change this:
compile('com.android.support:multidex:1.0.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}
To this:
compile('com.android.support:multidex:1.0.0');
the bolds module is used sometimes to fix Duplicated dexLibs
Regards
Your com.facebook.android:facebook-android-sdk:4.1.0 library is messing with parse as both use same bolts-android module internally and having a different version of this module. Try to exclude this module from any of parse or facebook gradle dependency.
compile('com.facebook.android:facebook-android-sdk:4.1.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}
I was having the same problem and When I run ./gradlew yourModuleName:dependencies by the terminal, I found exactly which two libraries are messing with each other having a different version of the same module internally.

Android - Duplicate Entry Error - How do I use one class from one JAR file when it exists in two JAR files without running into this error?

How do I get my code to use only one class from one JAR file when the same class from two JAR files exist in the files ormlite-android-4.6.jar & ormlite-core-4.45.jar without running into this error?
Here is a copy of my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.android.engineering"
minSdkVersion 16
targetSdkVersion 21
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.2.4'
compile 'joda-time:joda-time:2.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/butterknife-5.1.2.jar')
compile files('libs/com.google.guava_1.6.0.jar')
compile files('libs/com.springsource.org.junit-4.10.0.jar')
compile files('libs/commons-collections-3.2.1.jar')
compile files('libs/dagger-1.1.0.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/opencsv-3.3.jar')
compile files('libs/ormlite-android-4.6.jar')
compile files('libs/ormlite-core-4.45.jar')
compile files('libs/log4j-1.2.16.jar')
compile files('libs/icepick-2.3.jar')
compile files('libs/mockito-core-1.9.5.jar')
}
Here is the error I get:
:app:packageAllDebugClassesForMultiDex FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/j256/ormlite/dao/BaseDaoImpl$1.class
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.131 secs
The code I think is trying to use BaseDaoImpl.class which both exists in package com.j256.ormlite.dao.BaseDaoImpl in both ormlite-android-4.6.jar & ormlite-core-4.45.jar. How do I get it to use one class from one JAR file without running into this error?
You can use
compile ("net.danlew:android.joda:2.9.0") {
exclude group: 'org.joda.time'
}
or to exclude module use
compile ("net.danlew:android.joda:2.9.0") {
exclude module: 'jode-time'
}
Run "gradlew dependencies" which will allow you to see all the libraries. You can use the "exclude" directive to remove duplicate libraries.
Look here to read more about the exclude directive: https://gradle.org/docs/current/userguide/dependency_management.html#sub:exclude_transitive_dependencies

Categories

Resources