I'm trying to use the gcloud-java-datastore library in an Android app project. However, I keep running into the following error when trying to build:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: ... [one of several different classes]
I've tried excluding various dependencies (e.g. com.google.guava) from gcloud-java-datastore (v0.2.8) in build.gradle to get it to compile. If I exclude com.google.api.grpc, com.google.guava, com.google.api-client, and one of datastore-v1-protos or protobuf-java, I can get it to compile successfully. However, excluding either one of those last two dependencies breaks the core functionality of the library.
Is it even possible to use this library in Android? If so, what am I doing wrong?
Ok, figured it out. I downloaded and extracted datastore-v1-protos-1.0.1.jar, removed everything except the com/google/datastore folder, made a new jar, and included that as a library in my Android Studio project. Then I added the gcloud-java-datastore library to build.gradle with the following exclusions:
compile('com.google.cloud:gcloud-java-datastore:0.2.8') {
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
exclude group: 'com.google.guava', module: 'guava-jdk5'
exclude group: 'com.google.cloud.datastore', module: 'datastore-v1-protos'
}
and the following packagingOptions:
packagingOptions {
pickFirst 'META-INF/INDEX.LIST'
pickFirst 'META-INF/services/io.grpc.ManagedChannelProvider'
pickFirst 'META-INF/io.netty.versions.properties'
pickFirst 'META-INF/maven/com.google.guava/guava/pom.xml'
pickFirst 'META-INF/maven/com.google.guava/guava/pom.properties'
}
Related
I'm in the process of porting my FloatingActionButtonSpeedDial library to Compose and I've reached the step where I should publish the new Compose library to maven central but, when I generate the AAR, all the composable classes throw an Unresolved reference.
The crazy thing is that the the enum on the same package is perfectly fine and so is the AAR of the classic view library. So, the issue seems to affect only functions annotated with #Composable.
The issue happens with both a debug and release AAR so should not depend on minimization on release.
And of course the issue does not happen if I import the gradle module directly instead of using the AAR.
Do I need to do something special to generate an AAR with Composable?
This is build.gradle of the library module
The issue is caused by the packagingOptions:
packagingOptions {
resources {
exclude '.readme'
exclude 'LICENSE.txt'
exclude 'fabric/*.properties'
// Exclude the Firebase/Fabric/other random properties files
exclude '/*.properties'
// Exclude AndroidX version files
exclude 'META-INF/*.version'
// Exclude consumer proguard files
exclude 'META-INF/proguard/*'
exclude 'META-INF/*.properties'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/NOTICE.txt'
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
exclude 'META-INF/*.kotlin_module'
// for byte-buddy
exclude "META-INF/licenses/ASM"
pickFirst "win32-x86-64/attach_hotspot_windows.dll"
pickFirst "win32-x86/attach_hotspot_windows.dll"
}
}
And, in particular by the exclude 'META-INF/*.kotlin_module': this file is needed to access top-level members.
It would be better clear this exclusion list and only add what's necessary to get the project to build.
The scope of these classes seems to be package private, compared to class SpeedDialState. Maybe take a look at other composable libraries, in order to see how they do it:
https://github.com/jetpack-compose/jetpack-compose-awesome#libraries
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
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/
I replaced Java's Date classes with Joda's DateTime classes recently in my Android app. I use Jackson for parsing json. I added the following lines to my build.gradle file
compile com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.3
compile net.danlew:android.joda:2.7.1
It broke my build. The error message is duplicate files during packaging of APK. It also suggested the following option
android {
packagingOptions {
exclude 'org/joda/time/format/messages_da.properties'
}
}
There are many such files like that in JodaTime like "messages_da.properties", "messages_fr.properties". I believe those are used to provide locale based formatting.
My hunch says that these files should not be excluded. If experts out there can provide a solution for this, it would be great
This is actually an issue that results from depending on multiple joda-time modules in your project.
To fix this, you should exclude any duplicate joda-time module(s) from any dependency in your project that contains a duplicate joda-time module.
To find out what dependencies are including the duplicate joda-time, use the command ./gradlew app:dependencies to list your complete dependency graph. Then look through the list of dependencies and find the ones that includes the duplicate joda-time module. Then exclude joda-time from any dependency that includes a duplicate of it. After doing this your app will build fine.
Example of how to exclude joda-time from a dependency:
// An offending dependency that contains a duplicate joda-time.
compile('com.some.project:some-module:0.1') {
// Exclude joda-time from this dependency to remove the errors.
exclude module: 'joda-time'
}
This is the correct way to handle dependency conflicts.
I solved this issue like
android {
packagingOptions {
exclude 'org/joda/time/format/*.properties'
}
}
My dirty solution:
android {
packagingOptions {
exclude 'META-INF/maven/joda-time/joda-time/pom.properties'
exclude 'META-INF/maven/joda-time/joda-time/pom.xml'
pickFirst 'org/joda/time/format/messages.properties'
pickFirst 'org/joda/time/format/messages_cs.properties'
pickFirst 'org/joda/time/format/messages_da.properties'
pickFirst 'org/joda/time/format/messages_de.properties'
pickFirst 'org/joda/time/format/messages_en.properties'
pickFirst 'org/joda/time/format/messages_es.properties'
pickFirst 'org/joda/time/format/messages_fr.properties'
pickFirst 'org/joda/time/format/messages_it.properties'
pickFirst 'org/joda/time/format/messages_ja.properties'
pickFirst 'org/joda/time/format/messages_no.properties'
pickFirst 'org/joda/time/format/messages_nl.properties'
pickFirst 'org/joda/time/format/messages_pl.properties'
pickFirst 'org/joda/time/format/messages_pt.properties'
pickFirst 'org/joda/time/format/messages_ru.properties'
pickFirst 'org/joda/time/format/messages_tr.properties'
}
}