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
Related
Is there a way to exclude jar from aar? there are classes.jar and lint.jar in appcompat-1.2.0.aar . I want to exclude lint.jar when I implmentation 'androidx.appcompat:appcompat:1.2.0'
when I place implmentation 'androidx.appcompat:appcompat:1.2.0' to build gradle , my customized Lint rules will donot work. Because there is a lint.jar in appcomat.aar, so I want exclude lint.jar from appcomat.aar.
Because lint is just a jar in appcompat.aar, There is no lint dependency in pom.xml, So I cannot use blow code to exclude lint.jar :
implementation('androidx.appcompat:appcompat:1.2.0') {
exclude group: 'androidx.appcompat', module: 'lint'
}
You can use something like
configurations {
all*.exclude group: 'androidx.appcompat:appcompat', module: 'lint'
}
in your app level build.gradle file.
This basically excludes some of the modules inside the libraries which you do not need to use.
Group specifies the package name of the dependency you have imported, and module specifies the particular module that you wish to exclude.
I am working on a project for a client. The project seems to work fine in the old Android Studio, but ever since I updated my studio to 2.2.2, I am getting the sync error when trying to run the app, the error message is as posted below.
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: /home/empressum/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient-android/4.3.5.1/eecbb0b998e77629862a13d957d552b3be58fc4e/httpclient-android-4.3.5.1.jar
File2: /home/empressum/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3/5b0002c5fb66867ca919be0fbd86de1cfaf76da7/httpmime-4.3.jar
You might also want to check if you have 2 references of the same library or .jar included and remove the duplicate reference.
Guess you are using dependency which is conflicting with androids supplied jars. Add
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
in your gradle.
Add following into respective build.gradle file
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
}
You are using two many libraries files for http call instead use jar file on libs or add some dependency in gradle.
The error went when I downloaded the project zip file again and run it. But this time when Android Studio asked me to update the gradle file, I denied. I dont know if this explains the error, but now the project is running fine on any device I connect.
I'm having trouble adding the Jackson Parser dependency to my project.
Currently I'm using these lines of code on my build.gradle:
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
The only Class I need is the ObjectMapper that I know it is in databind package. When I added these lines in the gradle I pressed the sync and everything did correctly.
The problem was running the project on the emulator, this error showed up in Messages in Android Studio:
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/NOTICE File1:
C:\Users\Igor.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.7.2\84ffa765dd258dbab8695963c41308b054f3a1cb\jackson-databind-2.7.2.jar
File2:
C:\Users\Igor.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.7.2\8b8310381b690e317f5f0574e9b2dd7034778b4c\jackson-core-2.7.2.jar
I tried to left only the databind library but I got no lucky with that. Same error.
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
I tried Build -> Clean Project and deleting the .gradle/cache but no luck either.
I have no clue what this could be. Any suggestions?
Add
android {
...
packagingOptions {
exclude 'META-INF/NOTICE' // It is not include NOTICE file
exclude 'META-INF/LICENSE' // It is not include LICENSE file
}
...
}
in your build.gradle .
To resolve the problem entirely I added all of these:
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
implementation 'com.squareup.retrofit2:converter-jackson:2.7.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.10.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.3'
try this..
ref :-
https://mobikul.com/how-to-use-jackson-parser/
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'
}
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.