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'
}
}
Related
I'm facing a situation where some packages import the same native library:
> 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs:
- ~/.gradle/caches/transforms-3/7d9d92dc8ec1ba2e45aff2ecbb549550/transformed/jetified-react-native-0.68.2/jni/arm64-v8a/libc++_shared.so
- ~/.gradle/caches/transforms-3/e21c7f468f769020a3f8f2f5f3ed5664/transformed/jetified-libvlc-all-3.3.10/jni/arm64-v8a/libc++_shared.so
The standard solution is to use pickFirst:
packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
The thing is that, in my example as seen above, "first" here is the react-native file. I want to pick the libvlc file.
As far as I know, I can't exclude files based on the source package name.
How can I tell gradle to "pickLast" or "pickSomethingElseThanFirst"?
Thank you
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 have two Gradle modules for Android, one is a library and one is an application, and the application has a dependency on the module, like so: compile project(path ':library' configuration: 'debug')
The problem is that both modules use JNI, so they both packagelibc++_shared.so
from the NDK, causing:
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException:
Duplicate files copied in APK lib/armeabi-v7a/libc++_shared.so
I tried using packagingOptions, but it seems like I can only use that to completely exclude that file from being packaged at all, not just from being copied from the other module?
What type of packagingOptions have you tried to use? Probably, exlude? It looks like pickFirst should work for you. In this case you explicitly tell Gradle that you know about the problem and accept any of these files. Depending on the architectures you support you may need only some of the lines. You can find details in documentation
android {
// some stuff
packagingOptions {
pickFirst 'lib/armeabi-v7a/libgnustl_shared.so'
pickFirst 'lib/arm64-v8a/libgnustl_shared.so'
pickFirst 'lib/x86_64/libgnustl_shared.so'
pickFirst 'lib/x86/libgnustl_shared.so'
}
}
Let's say my project is dependent on two libraries A and B. These libraries are dependent on the same version of a library C. Library C is dependent on a couple of shared library files D. To use library C, libraries A and B both include D in their jniLibs directories.
Now, the issue here is that when I attempt to build this project with the dependencies configured:
compile('group:A:1.0#aar')
compile('group:B:1.0#aar') {
exclude group: 'group', module: 'C'
}
I receive an error stating that there are duplicate D files. How can I go about informing gradle to ignore certain jniLibs from only one of my libraries? Is there an exclude analog for jniLibs transitive dependencies?
I was able to achieve this via gradle by forcing gradle to just use the first version of the shared library that it found:
android {
packagingOptions {
pickFirst 'lib/armeabi/D.so'
pickFirst 'lib/x86_64/D.so'
pickFirst 'lib/armeabi-v7a/D.so'
pickFirst 'lib/x86/D.so'
pickFirst 'lib/arm64-v8a/D.so'
}
}
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'
}