Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate files during packaging of APK, how to include several licenses in gradle

Tags:

android

gradle

I'm including 2 Apache licensed libraries into my Android app, when I attempt to generate the application I'm having the infamous "Duplicate files during packaging" error.

My first attempt to solve was, as suggested in a lot of places (e.g.), to exclude the files, it worked and my apk was generated.

Then I realized that since 0.9.1. Gradle includes pickFirst option to place into the apk the first license found during compilation time.

 packagingOptions {
    pickFirst 'META-INF/LICENSE.txt'
    pickFirst 'META-INF/NOTICE.txt'
}

Problem is, Notice.txt contains only information about one of the licensed libraries, not both. For example, notice.txt of Apache Commons Codec is:

Apache Commons Codec Copyright 2002-2011 The Apache Software Foundation

This product includes software developed by The Apache Software Foundation (http://www.apache.org/).

-------------------------------------------------------------------------------- src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java contains test data from http://aspell.sourceforge.net/test/batch0.tab.

Copyright (C) 2002 Kevin Atkinson ([email protected]). Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.


and Joda Time's:

============================================================================= = NOTICE file corresponding to section 4d of the Apache License Version 2.0 = ============================================================================= This product includes software developed by Joda.org (http://www.joda.org/).

My question is, is there a way to "merge" the license and notice files automatically? I assume this is a common problem so I guess I'm not the first one facing it.

like image 684
Guillermo Merino Avatar asked Oct 27 '25 20:10

Guillermo Merino


1 Answers

There is a new "merge" packagingOption that looks like it will avoid this error while still allowing you to include important things like open source licenses.

(I am not a lawyer and not a gradle expert so make sure you understand how to honor your own licenses)

It combines duplicates into one file.

Docs: https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/PackagingOptions

Example:

 packagingOptions {
    merge 'META-INF/LICENSE.txt'
    merge 'META-INF/LICENSE'
    merge 'META-INF/NOTICE.txt'
    merge 'META-INF/NOTICE'
    merge 'META-INF/ASL2.0'
}
like image 155
cottonBallPaws Avatar answered Oct 29 '25 10:10

cottonBallPaws