Android Gradle plugin 0.7.0: “duplicate files during packaging of APK”

后端 未结 20 2455
谎友^
谎友^ 2020-11-22 08:51

Using Android Gradle plugin 0.7.0 with the following build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependenci         


        
相关标签:
20条回答
  • 2020-11-22 09:12

    In my case I only need to add to project's build.gradle file:

    android {
      packagingOptions {
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
      }
    
       ...
    }
    
    0 讨论(0)
  • 2020-11-22 09:15

    The same problem when I used 'org.springframework.android:spring-android-rest-template:2.0.0.M1' in Android Studio 1.0.1. I need include this in build.gradle

    android{
    ...
        packagingOptions{
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
        }
    ...
    }
    
    0 讨论(0)
  • 2020-11-22 09:16

    The problem is that the META-INF folder won't get filtered so multiple entries of NOTICE or LICENSE cause duplicates when building and it is tryed to copy them together.

    Dirty Quick Fix:

    Open the .jar file in your .gradle/caches/... folder (with a zip compatible tool) and remove or rename the files in the META-INF folder that cause the error (usally NOTICE or LICENSE). (I know thats also in the OP, but for me it was not really clear until I read the google forum)

    EDIT:

    This was fixed in 0.7.1. Just add the confilcting files to exclude.

    android {
        packagingOptions {
            exclude 'META-INF/LICENSE'
        }
    }
    
    0 讨论(0)
  • 2020-11-22 09:21

    Same here with

    dependencies {
        compile 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.0'
    }
    
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    

    I lost like 2 days for that weird error... Why is this still happening in gradle 1.0.0 ? That is very disturbing for newbies... Anyway, thanks for that info i thought it was on my code :)

    0 讨论(0)
  • 2020-11-22 09:23

    Important to know in what file it comes to this error (in you example it is META-INF/LICENSE.txt) , in my case it was in META-INF/LICENSE [without ".txt"], and then in the file META-INF/ASL2.0 so I added to my build.gradle this lines:

    android {
        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/ASL2.0'
        }
    }
    

    Very important (!) -> add the name of the file in the same style, that you see it in the error message: the text is case sensitive, and there is a difference between *.txt and *(without "txt").

    0 讨论(0)
  • 2020-11-22 09:24

    As of Android Studio version 0.8.14

    You should add:

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

    to your build.gradle file.

    History:

    According to comment 14 in this bug: https://issuetracker.google.com/issues/36982149#comment14 this is a bug in v0.7.0 of the Android Gradle plugin, and is due to be fixed soon in 0.7.1.

    Here are the notes from that bug about the addition for 0.7.1:

    0.7.1 is out with the fix for this.

    The DSL to exclude files is:

    android {
        packagingOptions {
            exclude 'META-INF/LICENSE.txt'
        }
    }
    

    You can add as many exclude statement as you want. The value is the archive path. No wildcard or glob support yet.

    Filenames "LICENSE.txt" and "NOTICE.txt" are case sensitive. Please try out with "license.txt" and "notice.txt" as well.

    0 讨论(0)
提交回复
热议问题