Android studio gradle duplicate files dagger compiler - android

having strange problem after updating android studio to 0.4.0 and gradle plugin to 0.7.1 and gradle version to 1.9 with dagger compiler
build.gradle
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-v13:19.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.dagger:dagger:1.2.0'
compile 'com.squareup.dagger:dagger-compiler:1.2.0'
}
on build getting this error
Execution failed for task ':MyApplication:packageDebug'.
Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
File 1: C:\Users\Mantas.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger-compiler\1.2.0\22633bb84433e03d345a83e7b0c08c66768be30\dagger-compiler-1.2.0.jar
File 2: C:\Users\Mantas.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger-compiler\1.2.0\22633bb84433e03d345a83e7b0c08c66768be30\dagger-compiler-1.2.0.jar
if dagger compiler lines is commented everything works fine
how can i solve this problem?
thanks
EDITED
fixed problem, check
https://plus.google.com/+HugoVisser/posts/7Wr3FcdNVxR

If you know which files are being duplicated you can always compile them with exceptions like this:
dependencies {
compile('com.squareup.dagger:dagger:1.2.0') {
exclude module: 'moduleName' //by artifact name
exclude group: 'groupName' //by group
exclude group: 'com.unwanted', module: 'moduleName' //or by both
}
compile 'com.squareup.dagger:dagger-compiler:1.2.0'
}
Just be sure that when you are doing this you enclose the dependancy in () to use the enclosure or it wont work.

Related

Error: android defines classes that conflict with classes now provided by Android , when we start to generate release build

I had several libraries conflict issues. That i resolved by adding
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents'
exclude module: 'xmlParserAPIs'
exclude module: 'xpp3'
exclude module: 'opengl-api'
}
}
But still following error present. And i am unable to build signed apk.
I have tried project clean/rebuild option.
Error: android 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]
Thanks in advance for your help.
Problem
How to see which dependency is creating conflicts. It is same like shooting in dark.
Solution
Some AS plugin that will show you which projects dependency hierarchy. You can find where issue presents exactly and solve that.
Gradle View is an Android Studio plugin that you can install and show dependency hierarchy.
Methods Count is another plugin, it also shows dependency tree.
The error may be comes from different module but if issue is httpcomp... or xpp3 then
I just add these lines of code in app Gradle
dependencies {
......
configurations {
all*.exclude group: 'xpp3', module: 'xpp3'
implementation.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
}
done

More than one file was found with OS independent path 'META-INF/LICENSE'

When I build my app, I get the following error:
Error: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'META-INF/LICENSE'
This is my build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "cn.sz.cyrus.kotlintest"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions{
annotationProcessorOptions{
includeCompileClasspath = true
}
}
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'*/
}
}
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 "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
compile 'com.github.GrenderG:Toasty:1.2.5'
compile 'com.orhanobut:logger:1.15'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.umeng.analytics:analytics:latest.integration'
compile 'ai.api:libai:1.4.8'
compile 'ai.api:sdk:2.0.5#aar'
// api.ai SDK dependencies
compile 'com.google.code.gson:gson:2.8.0'
compile 'commons-io:commons-io:2.4'
compile 'com.android.support:multidex:1.0.1'
}
When I add this code to my build.gradle file,
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
This error would be solved, but another problem will happen. Like this:
java.lang.NoClassDefFoundError: com.squareup.leakcanary.internal.HeapAnalyzerService
at com.squareup.leakcanary.LeakCanary.isInAnalyzerProcess(LeakCanary.java:145)
at cn.sz.cyrus.wemz.TestApplication.onCreate(TestApplication.kt:32)
Who has ideas how to solve this?
You can add this in yourProject/app/build.gradle inside android{}. The exclude function adds the named resource to the list of resources that are not packaged in the APK.
android {
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")
exclude("META-INF/*.kotlin_module")
}
}
The exclude function is deprecated in 7.0.2 and you should use something similar to this:
android {
...
packagingOptions {
resources.excludes.add("META-INF/*")
}
}
In my case it was enough to exclude only path 'META-INF/DEPENDENCIES' on yourProject/app/build.gradle inside android{} . Here it is
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
And then do Clean Project and Rebuild Project.
The solutions here didn't help me, but this link did.
If you have a library that's adding some android .so files –like libassmidi.so or libgnustl_shared.so– you have to tell gradle to pick just one when packaging, otherwise you'll get the conflict.
android {
packagingOptions {
pickFirst 'lib/armeabi-v7a/libassmidi.so'
pickFirst 'lib/x86/libassmidi.so'
}
}
I was having this issue when using a React Native app as a library in an Android project.
Basically when gradle puts together the apk file, it copies content from all the compile dependencies, It is intelligent enough to see that there is a duplicate file..coming from two different jar files. This could be any file like a.txt or META-INF/DEPENDENCIES. It might be best to exclude these files using the below, in case the file is present there only for informational purposes.
android{
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
Or if in case, the file is a mandatory file like a class file, that has been duplicated across two jar dependencies that are related to each other, it is best to find alternatives to these jars, in the way of a more compatible version.
I have faced a similar issue working in a multiple modules app environment:
Error: Execution failed for task
':app:transformResourcesWithMergeJavaResForDebug'. More than one file
was found with OS independent path 'META-INF/AL2.0'
This issue was being reported by several of these modules of mine and none of the above solutions were fixing it.
Turns out, I was using version Coroutines 1.3.6 which seemed to be embedding META-INF/AL2.0 which was already embedded by another of the libraries I was using. To fix it, I have added the following code snippet to the build.gradle of the module that was failing:
configurations.all {
resolutionStrategy {
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
}
}
Given that it was happening on multiple modules, I have moved that resolutionStrategy code to my project level build.gradle.
Everything worked after that.
Had similar message
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'constant-values.html'
To resolve it, I had to enable packages view(1) in Android Studio, then browse through the tree to libraries, and locate the duplicates(2)
Then, ctrl+alt+f12 (or RMB menu)(3) - and found libraries which caused the issue.
Made list of files inside those libs which caused the issues, and wrote them to app's build.gradle file inside android section. Other option is to deal with the library, containing duplicate files
packagingOptions {
exclude 'allclasses-frame.html'
exclude 'allclasses-noframe.html'
<..>
It's perfectly safe to exclude all meta-info files which are there just for documentation and information purposes:
android{
packagingOptions {
exclude 'META-INF/*'
}
}
Source: https://stackoverflow.com/a/49101232/13093413
Add the following in app level gradle file inside android{}
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'
exclude("META-INF/*.kotlin_module")
}
This happens when using
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0
And is fixed in next version
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1
For Gradle 7.2 and later
Add in-app Gradle file
android {
packagingOptions {
resources.excludes.add("META-INF/*")
}
}
I was having the same problem and I tried this
Error: More than one file was found with OS independent path
'META-INF/proguard/androidx-annotations.pro'
Solution:
All you have to do to fix this is to add this to the android { } section in your app's 'build.gradle'
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
I has encountered the same error, and I found that it resulted from different modules contained the same classes from different packages.
e.g. One used androidx package, and the other used pre-androidx
I solved it by migrating the pre-androidx module to androidx using built-in feature of Android Studio: "Refactor --> Migrate to Androidx..." without excluding anything.
For your situation, you may check if you have any dependency mismatches among modules.
I have read all the answers related to getting this message in Android Studio:
More than one file was found with OS independent path
'META-INF/LICENSE'
but in this case excluding classes is no neccessary, we only need to exclude 'META-INF/DEPENDENCIES', this can be done inside the /app/build.gradle:
android{
...
...
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
I my app, I was adding the jar dependencies like this:
implementation files('libs/json-simple-1.1.1.jar')
But I realised that they were already added because of the following first line in dependencies:
implementation fileTree(include: ['*.jar'], dir: 'libs')
This line adds all the jars in lib folder to app dependency.
Hence after removing the extra dependency implementation files('libs/json-simple-1.1.1.jar')
it is working fine.
Based on the answers provided by #JohnnyLambada and #Shaaban Ebrahim
For excluding nested files, I used the following.
packagingOptions {
resources.excludes.add("META-INF/**/*")
}
PS: Not spamming with same answer, but just a suggestion if you get an error something like
4 files found with path 'META-INF/gradle/incremental.annotation.processors'.
which catches errors from nested directories and FYI I had setup my dependencies using kotlin-dsl
I updated Studio from Java 7 to Java 8, and this problem occurred. Then I solved it this way:
android {
defaultConfig {
}
buildTypes {
}
packagingOptions{
exclude 'META-INF/rxjava.properties'
}
}
This work for me
packagingOptions {
exclude 'META-INF/*'
}
Adding
android.useAndroidX=true
android.enableJetifier=true
to gradle.properties worked for me.
This error is caused by adding a support library instead of AndroidX.
Make sure you use which one:
for AndroidX:
dependencies {
def multidex_version = "2.0.1"
implementation 'androidx.multidex:multidex:$multidex_version'
}
If you aren't using AndroidX:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Also in manifest use the application class name instead of "android.support.multidex.MultiDexApplication" in the application tag(my application class name is G):
the mistake:
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
right:
<application
android:name=".G" >
...
</application>
Since it's not already mentioned, you may alternatively merge the files to stay in accordance with license requirements (or just use pickFirst as stated by Daniel Reina).
packagingOptions {
merge "META-INF/LICENSE"
merge "META-INF/AL2.0"
merge "META-INF/LGPL2.1"
}
Reference: Gradle API 4.2 Packaging Options
I had a similar problem. i was getting the error message -
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'javax/annotation/WillCloseWhenClosed.java'
As stated in some of the answers above, using the below code works
'packagingOptions {
exclude 'allclasses-frame.html'
}'
But i was getting this error for 20 different files, so after excluding 20 files, i stopped and tried to find a decent solution. I had also encountered the
'Unable to execute dex: Multiple dex files' error.
I finally managed to solve this.
Firstly (as in my case WillCloseWhenClosed.java was the duplicate file), in android studio you have an option of 'search everywhere'. Write and search for the file there. There i found multiple instances of this file. So i clicked on both instances and saw their location by right clicking on the file and seeing its location when they opened in android studio.
Secondly, I figured out that i had some dependencies in gradle file. I was using the below code
dependencies {
compile 'com.google.api-client:google-api-client:1.23.0'
}
and also i had their same zip packages in the location :\Users\user\AndroidStudioProjects\git\appname\app\libs\google-http-client-1.23!.
So this was redundant and thats why gradle is finding 2 files. So i deleted my zip packages and it solved the errors for me. Be carefull while doing this. You have to figure out which is the correct file or package to be deleted.
Thirdly, gradle also makes a zip of these bug files in this location (At least for me it made) - C:\Program Files\Android\Android Studio\gradle\m2repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar!
so i went and deleted the jsr305-1.3.9.jar file from here also.
If you are still confused, just go the 'search everywhere' in android studio, find instances of your file there and you would have to delete one of them. Take your time and figure out which one.
I'm having same problem and I tried this
Error:
More than one file was found with OS independent path 'META-INF/library_release.kotlin_module'
Solution:
android {
packagingOptions {
exclude 'META-INF/library_release.kotlin_module'
}
}
Worked for me. Add these to your app's build.gradle within the android{} block.
packagingOptions {
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
}
in gradle 7.2 and above you can fix the problem like this:
in your app/build.gradle in android block:
packagingOptions {
resources.excludes.add("META-INF/notice.txt")
resources.merges.add("META-INF/LICENSE")
resources.merges.add("META-INF/AL2.0")
resources.merges.add("META-INF/LGPL2.1")
}
put this inside the build.gradle (Module AppName)
android {
// ....
packagingOptions{
pickFirst "androidsupportmultidexversion.txt"
}
}
I faced this issue, first with some native libraries (.so files) and then with java/kotlin files. Turned out I was including a library from source as well as referencing artifactory through a transitive dependency. Check your dependency tree to see if there are any redundant entries. Use ./gradlew :app:dependencies to get the dependency tree. Replace "app" with your module name if the main module name is different.
Try to remove multidex from default config and check the build error log.
If that log is some relatable with INotification class. Use this in android{}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
This helps me.
In many of the answers on SO on this problem it has been suggested to add exclude 'META-INF/DEPENDENCIES' and some other excludes. However none of these worked for me. In my case scenario was like this:
I had added this in dependancies:
implementation 'androidx.annotation:annotation:1.1.0'
And also I had added this in gradle.properties:
android.useAndroidX=true
Both of these I had added, because I was getting build error 'cannot find symbol class Nullable' and it was suggested as solution to this on some of answers like here
However, eventually I landed up in getting error:
More than one file was found with OS independent path 'androidsupportmultidexversion.txt'
No exclude was working for me. Finally I just removed those added lines above just out of suspecion (Solved 'cannot find symbol class Nullable' in some alternative way) and finally I got rid of this "More than one file was found with OS..." build error. I wasted hours of mine. But finally got rid of it.
If you have this problem and you have a gradle .jar dependency, like this:
implementation group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26'
Interval versions until one matches and resolves the excepetion,and apply the best answer of this thread.`
If you work with multi module project and face this issue while espresso testing, you need to add packagingOptions code each gradle file. In my case , I added below code for each gradle file.
packagingOptions {
exclude 'META-INF/lib_release.kotlin_module'
}

Gradle: Cant exclude one of two log4j dependencies?

Occuring error
While trying to build an android studio project with gradle i recieve this error:
Execution failed for task ':app:transformResourcesWithMergeJavaResForPlainDebug'.
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException:
Duplicate files copied in APK org/apache/log4j/lf5/config/defaultconfig.properties
File1: ...\app\libs\tn5250j.jar
File2: ...\app\build\intermediates\exploded-aar\xxx\xxx\jars\libs\log4j-1.2.17.jar
In two included .jars the library log4j is used. I must include both libs to my android application. One of them is an .aar file, the other is a .jar.
Gradle settings
Dependencies from my build.gradle:
dependencies {
debugCompile 'xxx#aar'
releaseCompile 'xxx#aar'
compile files('libs/commons-net-3.5.jar')
compile files('libs/jackson-core-2.8.1.jar')
compile files('libs/jackson-databind-2.8.1.jar')
compile files('libs/jackson-annotations-2.8.1.jar')
compile files('libs/tn5250j.jar')
}
Packaging options from my build.gradle:
packagingOptions {
exclude 'main/AndroidManifest.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
}
I have no idea what tn5250j.jar is but it looks like it's an UBER jar which is packing log4j inside. You could either exclude the log4j dependency from your build (since it's packed inside tn5250j.jar) or you tweak tn5250j.jar to remove log4jand use the "tweaked" jar instead. Eg:
dependencies {
...
compile files("$buildDir/tweaked/tn5250j-tweaked.jar")
}
task tweakTn5250j(type: Zip) {
from zipTree('libs/tn5250j.jar').matching {
exclude 'org/apache/log4j/**'
}
destinationDir = "$buildDir/tweaked"
archiveName = 'tn5250j-tweaked.jar'
}
classes.dependsOn tweakTn5250j

Error compiling Android project after updating FindBugs to 3.0.1

After updating Findbugs plugin up to 3.0.1 version I can't compile multi module project in Android Studio. Also i use "com.google.code.findbugs:annotations:3.0.1" dependency for using FindBugs annotations (e.g. #SuppressFBWarnings).
I get following error while assembling project:
Execution failed for task ':presentation:packageAllDevelopDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: javax/annotation/CheckForNull.class
How can I fix it?
I resolved this issue, the cause was in adding to "com.google.code.findbugs:annotations:3.0.1" additional dependencies ('com.google.code.findbugs:jsr305:3.0.1' and 'net.jcip:jcip-annotations:1.0'). To fix it we need to exclude some transitive dependencies.
Replace:
dependencies {
compile "com.google.code.findbugs:annotations:3.0.1"
}
with
dependencies {
compile ("com.google.code.findbugs:annotations:3.0.1") {
exclude module: 'jsr305'
exclude module: 'jcip-annotations'
}
}
or with
dependencies {
compile ("com.google.code.findbugs:annotations:3.0.1") {
transitive = false
}
}
As suggested previously excluding module jsr305 worked for me, but I've used a different syntax due to importing a projest, not a module.
I was importing a library project present as indipendent project on my disk, so I had
compile project(path: ':shareLib')
To exclude module jsr305 I turned my code in
compile (project(path: ':shareLib')) {
exclude module: 'jsr305'
}

Android AssertJ 1.0.0 with Android gradle 1.1.1

Here is part of my build.gradle that has conflict:
...
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
...
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' )
...
The issue that I see in log:
WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (21.0.3) and test app (20.0.0) differ.
Apparently it removes conflicting dependency from the classpath. I'm not sure if it is gradle or android gradle plugin.
I've tried next:
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
exclude group: 'com.android.support', module: 'support-annotations'
}
But I still have compilation errors so dependency is excluded.
I've tried next:
configurations.all {
resolutionStrategy {
// fail eagerly on version conflict (includes transitive dependencies)
// e.g. multiple different versions of the same dependency (group and name are equal)
failOnVersionConflict()
// force certain versions of dependencies (including transitive)
// *append new forced modules:
force 'com.android.support:support-annotations:21.0.3'
// *replace existing forced modules with new ones:
forcedModules = ['com.android.support:support-annotations:21.0.3']
}
}
But looks like it doesn't work since it is not failing on the first conflict and I still have compilation errors.
What will be your suggestions?
UPDATE What do I mean by removing dependency - I see a lot of compile errors that assertj not found
I ran into the same issue. This fixed it for me:
testCompile('com.squareup.assertj:assertj-android:1.0.0'){
exclude group: 'com.android.support', module:'support-annotations'
}
The accepted answer didn't work for me. However, adding the following did work for me:
androidTestCompile 'com.android.support:support-annotations:23.0.1'
and:
testCompile 'com.android.support:support-annotations:23.0.1'
Based on https://stackoverflow.com/a/29947562/2832027
You need to change:
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
exclude group: 'com.android.support', module: 'support-annotations'
}
to:
compile('com.squareup.assertj:assertj-android:1.0.0') {
exclude group: 'com.android.support', module: 'support-annotations'
}
Also ensure that your test folder is called test and not androidTest

Categories

Resources