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 .
Related
More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
Above error occurs while building when I add implementation Apache lib
dependencies {
compile 'org.apache.httpcomponents:httpmime:4.2.6'
}
I am added google cloud dependency by
implementation ('com.google.cloud:google-cloud-storage:1.12.0'){
exclude group: 'com.google.guava'
}
but my build is failed with the following error
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- auto-value-1.2.jar (com.google.auto.value:auto-value:1.2)
I tried by disabling annotation processor
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/project.properties'
}
.................
.........
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
........................
I am getting following error
More than one file was found with OS independent path 'project.properties'
Add this part as dependencies:
compileOnly 'com.google.auto.value:auto-value:1.5.1'
annotationProcessor 'com.google.auto.value:auto-value:1.5.1'
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'
}
}
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'
}
}
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.