How to resolve Duplicate files copied in APK META-INF/rxjava.properties - android

I am using rxjava and rxvolley on my android aplication. When I try to run it I get this error
Execution failed for task ':testapp:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
File1: C:\Users\Daniel\.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.0\748f0546d5c3c27f1aef07270ffea0c45f0c42a4\rxjava-1.1.0.jar
File2: C:\Users\Daniel\.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.3\d2f725668bd22e21170381b23f8fbdf72c69d886\rxjava-2.0.3.jar
I have a exclude.gradle file like this
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/rxjava.properties'
exclude 'META-INF/rxjava.PROPERTIES'
exclude 'META-INF/RXJAVA.properties'
exclude 'META-INF/RXJAVA.PROPERTIES'
exclude 'META-INF/rxjava'
exclude 'META-INF/RXJAVA'
}
lintOptions {
abortOnError false
}
}
How can I fix this problem?

I had the same problem. The way I fixed it is adding the packagingOptions in app gradle as described in Duplicated file rxjava.properties
android {
defaultConfig {
}
buildTypes {
}
packagingOptions{
exclude 'META-INF/rxjava.properties'
}
}

I had the same issue.
In my case I am using Retrofit2 but I assume that the issue is with the rx libraries
This is the build.gradle (module:app) I am using and in my case works.
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'io.reactivex:rxandroid:1.1.0' //<-use this
compile 'io.reactivex:rxjava:1.1.3' //<-use this
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
Anyway there is one better solution as you can see on the top

I also have the same problem but easily removed duplicated "comment" all Rxjava related dependencies that it doesn't use in my code.
//RxJava removes or comment duplicated and not used dependencies.
// implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'
// implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
// implementation 'io.reactivex.rxjava2:rxjava:2.1.13'

I encountered the same issue and fixed it by putting below code in app/build.gradle file. Please note that you have to put '*' at the end of path to exclude all the files inside the folder. You will have to change the path of files to be excluded in the below code based on error description.
compileSdkVersion 25
buildToolsVersion "24.0.3"
packagingOptions {
exclude 'com/google/appengine/repackaged/org/apache/commons/codec/language/bm/*'
exclude 'com/google/appengine/repackaged/org/codehaus/jackson/impl/*'
exclude 'com/google/appengine/repackaged/org/apache/commons/codec/language/*'
}

I had this issue today and fixed this problem
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
//RxJava dependencies
compile 'io.reactivex.rxjava2:rxandroid:2.0.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.2'
compile 'org.reactivestreams:reactive-streams:1.0.0'

I also have this problem ,I also used the same method as you ,but because I hava two module ,I only chang it in the module which dependency Rxjava,Finally I I fixed it is adding the packaginOptions in app gradle
packagingOptions {
exclude 'META-INF/rxjava.properties'
}

If you are facing this issue in 2019 and above this is most probably because you are using the deprecated RxJava 2 CallAdapter.Factory ie
com.jakewharton.retrofit:retrofit2-rxjava2-adapter
you will have to remove that dependency and add this
implementation 'com.squareup.retrofit2:adapter-rxjava2:latest.version'
please get the latest version from here

Add this code in build.gradle.app
android {
...
...
...
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
}

Related

commons-logging defines classes that conflict with classes now provided by Android after Android Studio Update

I have updated Android Studio to version 3 and now seems unable to compile my project previously compiled without errors.
The error message is the follow
Error:Error: commons-logging defines classes that conflict with
classes now provided by Android. Solutions include finding newer
versions or alternative libraries that don't have the same problem
(for example, for httpclient use HttpUrlConnection or okhttp instead),
or repackaging the library using something like jarjar.
[DuplicatePlatformClasses]
The dependencies are
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:design:27.0.0'
compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
compile 'com.google.firebase:firebase-core:11.4.2'
}
and error seems caused by
compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
I already use exclude module: 'httpclient'
So why It doesn't compile?
Is this a bug of Android Studio 3 and\or included com.android.tools.build:gradle:3.0.0 plugin or I'm missing something? With the previous version no problem to compile exactly the same project.
Add to build.gradle located in app module
configurations {
all {
exclude module: 'httpclient'
}
}
If the problem is with commons-logging then it must be excluded too.
Add the following code in app/build.gradle
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}
Got the same issue. I have done below changes
configurations {
all{
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'org/apache/http/version.properties'
exclude 'org/apache/http/client/version.properties'
}
You should replace "compile" with "implementation" as it's deprecated in the latest gradle and exlude "org.apache.httpcomponents" from Google api client libraries:
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.http-client:google-http-client-gson:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
this solution was found here:
https://developers.google.com/google-apps/activity/v1/quickstart/android
Run in terminal, inside project folder:
./gradlew app:dependencies > dependencies.txt
Then check dependencies.txt to find who is using conflictive dependencies and act accordingly (check for updates, get rid of it, or use exclude as suggested by #Silverstorm)
If you want to continue with async-http then add below following code only in app/build.gradle
configurations {
all {
exclude module: 'commons-logging'
}
}
As 'org.apache.httpcomponents:httpclient:4.3.3' is deprecated after SDKversion 23 so
replace this:
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
with
compile 'org.apache.httpcomponents:httpclient:4.3.3'
I received these two errors today.
1. commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
2. httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
After struggling for sometime, I figured that I was using a Firebase library which was causing these errors.
implementation platform('com.google.firebase:firebase-bom:29.2.0')
So, I updated it:
implementation platform('com.google.firebase:firebase-bom:29.2.1')
And Invalidated Caches and Restarted the project and it worked like a charm.
Earlier BOM version of Firebase was also working fine.
implementation platform('com.google.firebase:firebase-bom:29.1.0')
Please don't update Firebase BOM version: 29.2.0
I removed commons-logging as suggested above, of course it crashed on some phone with Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;. How can Android claim the commons-logging is conflicting with Android API when the Android API doesn't contain any of those classes?!? There is no org.apache.commons.logging at https://developer.android.com/reference/packages :facepalm:
I've added back implementation 'commons-logging:commons-logging:1.0.4' to the build.gradle - Android Studio underlines it with red but gradle compiles happily. :facepalm:
Android :triple_facepalm:
if you are facing this issue because of org.apache.httpcomponents:httpmime dependency, then use this in your app level build.gradle file:
implementation('org.apache.httpcomponents:httpmime:4.5.12') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
implementation "org.apache.httpcomponents:httpcore:4.4.13"
I had to join multiple solutions from here. This is what worked for me:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
configureEach {
exclude module: 'httpclient'
exclude module: 'commons-logging'
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
}
Add this then sync your gradle
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
all*.exclude module: 'httpclient'
all*.exclude module: 'commons-logging'
}
in my case android studio couldn't recognize "httpclient"
so i couldn't use #Silverstorm answer.
instead found another answer:
Error: json defines classes that conflict with classes now provided by Android
which implies to add below could in app build.gradle:
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}

transform.TransformException in Android

I get an error when I try to use iText to generate a PDF at run time.
The error comes when the Application is run in device or geny Motion.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/lowagie/bc/asn1/ASN1Encodable.class.
My Gradle Code is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.visioneering.tfd"
minSdkVersion 15
targetSdkVersion 24
versionCode 5
versionName "1.5"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
android {
lintOptions {
checkReleaseBuilds false
}
}
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'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.github.florent37:materialtextfield:1.0.5'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.google.android.gms:play-services:10.2.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
compile 'com.googlecode.json-simple:json-simple:1.1'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.itextpdf:itext7-core:7.0.3'
compile 'com.itextpdf:itext-pdfa:5.5.11'
compile 'itext:itext:1.3.1'
compile 'org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.6'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Please help me to solve this problem.
duplicate entry: com/lowagie/bc/asn1/ASN1Encodable.class - that points to iText 2.1.7 or older, which is not known to be compatible with Android.
There are a couple of things wrong in your Gradle file:
compile 'com.itextpdf:itext-pdfa:5.5.11' - that points to the PDF/A add-on of iText 5, version 5.5.11, which is compatible with Android, but you still need the Android port of iText 5, which is called iTextG. So you need to add compile 'com.itextpdf:itextg:5.5.10'. Yes, 5.5.10, not 5.5.11, because there is no itextg:5.5.11. See http://repo1.maven.org/maven2/com/itextpdf/itextg/
I am guessing that you think the "a" in "pdfa" means Android, but it doesn't. It stands for PDF/A: the PDF spec for archiving (ISO 19005), see https://en.wikipedia.org/wiki/PDF/A. If you don't need archiving (you probably don't, in a typical Android app), so you probably need to remove compile 'com.itextpdf:itext-pdfa:5.5.11'
compile 'com.itextpdf:itext7-core:7.0.3' - this is iText 7, which is not compatible with Android. Remove that line.
compile 'itext:itext:1.3.1' - is an ANCIENT version of iText, and is probably what is causing your error. Remove that line.
compile 'org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.6' - this is something special, which I don't know enough about. It may or may not pull in another dependency of iText, which may or may not be the wrong version. Tag your question with flying-saucer to attract extra attention.

Error is Duplicate files copied in META-INF/LICENSE jackson files

gradle error
gradle file
These are my gradle console error and file as well
Suggest new ideas to resolve the error, I tried all previous solutions, didn't work.
You should use 10.2.0 instead of 10.0.1
No Need
compile 'com.firebase:firebase-client-android:2.5.2' // Remove this
Do this
compile 'com.google.firebase:firebase-auth:10.2.0'
compile "com.google.firebase:firebase-database:10.2.0"
Then
android {
.....
packagingOptions{
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
Finally Clean-Rebuild and Run .

Apache HttpClient Android (Gradle)

I have added this line to my build.gradle
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
and I want to use MultipartEntityBuilder in my code. However Android studio doesn't add the library to my code.
Can anyone help me with this?
If you are using target SDK as 23 add the below code in your build.gradle
android{
useLibrary 'org.apache.http.legacy'
}
Additional note here: don't try using the gradle versions of those files. They are broken (28.08.15). I tried over 5 hours to get it to work. It just doesn't.
not working:
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
Another thing don't use:
'org.apache.httpcomponents:httpclient-android:4.3.5.1'
It's referring to 21 API level.
The accepted answer does not seem quite right to me. There is no point dragging a different version of HttpMime when one can depend on the same version of it.
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5') {
exclude module: 'org.apache.httpcomponents:httpclient'
}
Try adding this to your dependencies:
compile 'org.apache.httpcomponents:httpclient:4.4-alpha1'
And generally if you want to use a library and you are searching for the Gradle dependency line you can use Gradle Please
EDIT: Check this one too.
None of the others worked for me. I had to add the following dependency, as explained here
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
because I was targeting API 23.
I resolved problem by adding following to my build.gradle file
android {
useLibrary 'org.apache.http.legacy'}
However this only works if you are using gradle 1.3.0-beta2 or greater, so you will have to add this to buildscript dependencies if you are on a lower version:
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
I searched over and over this solution works like a charm ::
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.anzma.memories"
useLibrary 'org.apache.http.legacy'
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
I don't know why but (for now) httpclient can be compiled only as a jar into the libs directory in your project.
HttpCore works fine when it is included from mvn like that:
dependencies {
compile 'org.apache.httpcomponents:httpcore:4.4.3'
}
Working gradle dependency
Try this:
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

Duplicate files during packaging of APK app-debug-unaligned.apk

I got this error Duplicate files during packaging of APK app-debug-unaligned.apk when put 2 jar files :
httpclient-4.3.5.jar
httpmime-4.3.5.jar
into the libs folder after Sync with Gradle and Run.
If user 1 jar file - httpmime-4.3.5.jar, I will not get this error.
Please help me how to avoid this error & still can use 2 jar files in above also,
Thanks,
p/s : I use Android Studio version 0.8.6.
Error Detail
Error:duplicate files during packaging of APK
...\app\build\outputs\apk\app-debug-unaligned.apk
Path in archive: META-INF/DEPENDENCIES
Origin 1: ...\app\libs\httpclient-4.3.5.jar
Origin 2: ...\app\libs\httpmime-4.3.5.jar
build.gradle
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.app'
minSdkVersion 9
targetSdkVersion 20
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.google.android.gms:play-services:5.2.08'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'de.hdodenhof:circleimageview:1.2.0'
compile files('libs/httpmime-4.3.5.jar')
}
UPDATE I changed from compile files('libs/httpmime-4.3.5.jar') to use Maven Link. I got same error again after put 2 maven link together:
compile 'org.apache.httpcomponents:httpmime:4.4-alpha1'
compile 'org.apache.httpcomponents:httpcore:4.4-alpha1'
This is the warning
Warning:Dependency org.apache.httpcomponents:httpclient:4.4-alpha1 is
ignored for debug as it may be conflicting with the internal version
provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency
org.apache.httpcomponents:httpclient:4.4-alpha1 is ignored for release
as it may be conflicting with the internal version provided by
Android.
In case of problem, please repackage it with jar to change the class packages
Please help me fix.
SOULITION I know good answer now by addding these lines will fix Duplicate files error :
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'
}
You can replace compile files('libs/httpmime-4.3.5.jar') with this compile 'org.apache.httpcomponents:httpmime:4.3.5'.
Also you are duplicating the dependencies compile fileTree(include: ['*.jar'], dir: 'libs') already includes compile files('libs/httpmime-4.3.5.jar')
update your build.gradle and add the following lines
android{
.
.
.
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE'
}
}
this will fix this error. I got the same error, doing this fixed it.
Please update this to your build.gradle file.
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
I updated gradle now it's working
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
add the below code to dependencies
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5') {
exclude module: 'org.apache.httpcomponents:httpclient'
}
now if you run that it will show you why it is telling duplicate may be because of META-INF/NOTICE, META-INF/LICENSE, add that first again run it may show other type.
add all like below under android section
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
definitely it will solve your problem.
remove all the dependancy file from the system before build.

Categories

Resources