In my gradle file, I have the following:
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
According to the documentation:
/**
* Adds an excluded paths.
* #param path the path, as packaged in the APK
*/
What does this mean? Could someone give me a real life example of why these exclusions would need to be made?
If you were to change the extension of a few aar files to zip and open them eventually you will have two aar files with files that with the same path.
SomeDependency-A.aar
-META-INF/LICENSE
...
SomeDependency-B.aar
-META-INF/LICENSE
...
When the aar dependencies are merged it fails because it tries to add the file LICENSE and it already exists.
We resolve this by excluding the duplicated files
android {
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
For Kotlin DSL (build.gradle.kts) and Android Gradle Plugin (AGP) version 7.0.0 and higher the exclude method is deprecated in favor of the resources.excludes property:
android {
// ...
packagingOptions {
resources.excludes += "META-INF/LICENSE*"
resources.excludes += "META-INF/NOTICE.txt"
// OR
// resources.excludes += setOf(
// "META-INF/LICENSE*",
// "META-INF/NOTICE.txt"
// )
}
}
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 have a multi-module Android application and when I build the release APK, I get this dex error:
java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/XX/package-info;
I do of course have a package-info file in all my modules and they all have the same name.
Why does dex even care about package-info files, and how can I configure it to ignore them?
Note: I do NOT want to enable multi-dex
The solution is to exclude the package-info files from the jar files.
Example code to use in build.gradle files
for java-modules:
jar {
exclude('com/**/package-info.*')
}
for android-modules:
android {
sourceSets.main.java.filter.exclude 'com/**/package-info.*'
}
Works with:
Android Studio 3.0 Canary 5
Gradle 4.1-milestone-1
Android gradle plugin: 3.0.0-alpha5
Note: you can of course only then exclude the package-info files if they don't contribute to your build!
e.g. when you use immutables style-configuration in your package-info file then you cannot exclude the files from the build, because then the names of the generated files may change!
Try with using packagingOptions inside android tag in build.gradle for app module.
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
More: Packaging
I added the latest Joda Time jar into my libs folder and added the library. when trying to run I get the following error:
Error:Execution failed for task ':Selfies:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE.txt
File 1: C:\Users\Dominic\Desktop\selfieapp\Selfies\Selfies\libs\commons-io-2.4.jar
File 2: C:\Users\Dominic\Desktop\selfieapp\Selfies\Selfies\libs\joda-time-2.8.1.jar
Not too sure what this means and how to fix it. Any help would be great!
Update yout build.gradle like this:
android {
...
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
you can exclude this file with packagingOptions in your build.gradle - but you should also have a look into joda-time-android or even better https://github.com/JakeWharton/ThreeTenABP
I have literally created a brand new Android Project on the latest Android Studio. The first thing I did was to add the `Realm' library to the project by adding the following to the gradle file:
compile 'io.realm:realm-android:0.80.3'
If I try to compile, I get the following error:
Note: C:\....\MainActivity.java uses or overrides a deprecated API.
Origin 2:
C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\io.realm\realm-android\0.80.3\7979d05ba7b919c53766bf98e31aaf0e9feb0590\realm-android-0.80.3.jar Error:duplicate files during packaging of APK
C:...\app\build\outputs\apk\app-debug-unaligned.apk Path in archive:
META-INF/services/javax.annotation.processing.Processor Origin 1:
C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\6.1.0\63735f48b82bcd24cdd33821342428252eb1ca5a\butterknife-6.1.0.jar
You can ignore those files in your build.gradle: android {
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor' } Error:Execution failed for task ':app:packageDebug'.
Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor File 1:
C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\6.1.0\63735f48b82bcd24cdd33821342428252eb1ca5a\butterknife-6.1.0.jar
File 2:
C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\io.realm\realm-android\0.80.3\7979d05ba7b919c53766bf98e31aaf0e9feb0590\realm-android-0.80.3.jar }
Any ideas?
It looks like you are also using Butterknife? Have you tried adding the below to your build.gradle:
android {
...
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
Adding this to the android plugin in build.gradle tends to fix these sorts of problems:
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
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/services/javax.annotation.processing.Processor'
exclude 'META-INF/*.kotlin_module'
}
}
Adding these on build.gradle as Specified in ButterKnife I/O page.
android{
....
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
lintOptions {
disable 'InvalidPackage'
}
I'm getting this error (AGAIN!) on android. Recently updated to the latest version of gradle 0.7.3 and also to the latest version of espresso framework (1.1) and I'm back to the infamous "duplicate file" bug.
Execution failed for task ':mobile:packageTesttype'.
Duplicate files copied in APK META-INF/LICENSE.txt File 1: /Users/mwolfe/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.2.4/dba4d4d224e2ca872af5be8d2992777583145478/httpmime-4.2.4.jar
File 2:
/Users/mwolfe/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.2.4/dba4d4d224e2ca872af5be8d2992777583145478/httpmime-4.2.4.jar
I already have set my build.gradle file to exclude these files. The app assembles fine for debug/release and runs fine, However building/running for test it fails. Specifically when I try to run instrument tests with the followng command is when I get the error mentioned above.
gradle connectedCheck
I have a library project as well and have tried every which way to add the exclusions to both build files. This specific dependency is from the library project. Both of them have the following exclusions
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
I've also tried with removing the META-INF part above as it shows in the espresso docs here: https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions
I know I can delete these files from the jars but it's quite a pain.
Try to include other variations too...Copy and paste this:
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}