title: How do I resolve "Duplicate files copied in APK META-INF/*"
body: <p>I am working at a commercial android application.
  I am also using some libraries licensed under different license types some of them stating the following:</p>
  
  <p><em>If the library has a "NOTICE" file with attribution notes, you must include that NOTICE when you distribute</em></p>
  
  <p>(One of them is licensed under <strong>Apache License 2.0</strong> for example).</p>
  
  <p>There is more than one library. When I do the build with <strong>gradle</strong> or with <strong>Android Studio</strong> I obtain the following build error:</p>
  
  <pre><code>* What went wrong:
  Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
  &gt; com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/license.txt
  </code></pre>
  
  <p>The answers that I found until now on the internet and stackoverflow suggest to remove the license.txt(notice.txt or other files that could interfere like this) from packaging by adding to <code>build.gradle</code> file the following:</p>
  
  <pre><code>packagingOptions {
      exclude 'META-INF/DEPENDENCIES.txt'
      exclude 'META-INF/LICENSE.txt'
      exclude 'META-INF/NOTICE.txt'
      exclude 'META-INF/NOTICE'
      exclude 'META-INF/LICENSE'
      exclude 'META-INF/DEPENDENCIES'
      exclude 'META-INF/notice.txt'
      exclude 'META-INF/license.txt'
      exclude 'META-INF/dependencies.txt'
      exclude 'META-INF/LGPL2.1'
  }
  </code></pre>
  
  <p>See for example: <a href="https://stackoverflow.com/questions/20827885/android-studio-0-4-duplicate-files-copied-in-apk-meta-inf-license-txt">Android Studio 0.4 Duplicate files copied in APK META-INF/LICENSE.txt</a></p>
  
  <p>According to the license of those libraries(<strong>Apache License 2.0</strong> for instance), the license and notice files should be <strong><em>included</em></strong>.</p>
  
  <p><strong>My question:</strong>  How can I add multiple files related to licensing(such as <em>license.txt</em>, <em>notice.txt</em> etc) from gradle into my project in order to be compliant with the licenses(<strong>technical detail:</strong> licences texts will be concatenated)?</p>