3

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 (kevina@gnu.org). 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.

Community
  • 1
  • 1
Guillermo Merino
  • 3,197
  • 2
  • 17
  • 34
  • 2
    Gradle has no means of taking two random text files, realize that they have commonalities (by some means) and then assemble them into a single file (by some means) that is legally valid. There may be a Gradle/Groovy way to concatenate them; you would need to discuss with your legal counsel whether that is a worthwhile exercise. – CommonsWare Jun 30 '15 at 12:48
  • 1
    Sounds like you would be better off writing your own LICENSE.txt file - you still need to provide one that covers your app, right? – Jolta Jun 30 '15 at 14:10
  • Thank you both for the comments. Yes, @Jolta my temporal solution is to write my own license and notice files, but I thought that maybe there was a way to automatize this and don't need to manually modify my files if a new library is added. I know it's not a big deal, but considering the number of apps that include > 1 library (probably with licenses) I was thinking that maybe there was an automatic way. – Guillermo Merino Jun 30 '15 at 14:36

1 Answers1

2

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'
}
Erhannis
  • 4,256
  • 4
  • 34
  • 48
cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171