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

后端 未结 20 2453
谎友^
谎友^ 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:07

    This bug still exists in 0.8+/1.10

    With Jackson

    compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.2.2'
    

    I had to include as well as the above suggestion before it would compile

    exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
    
    0 讨论(0)
  • 2020-11-22 09:09

    In my case I had to include several additional exclusions. It appears it doesn't like Regular expressions which would've made this a nice one-liner.

    android {
        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'
        }
    }
    
    0 讨论(0)
  • 2020-11-22 09:10
    packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
    }
    
    0 讨论(0)
  • 2020-11-22 09:10

    Removing .txt after LICENSE removed my error :

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

    This works for me:

    android {
       packagingOptions {
           exclude 'LICENSE.txt'
       }
    }
    
    0 讨论(0)
  • 2020-11-22 09:11

    If you want to do your part as developer, utilizing open source libraries, you should try including all those open source licenses within your apk. To do this, you can use the merge method in your packagingOptions.

    Example:

    packagingOptions {
            // This will get include every license and notice regardless of what dir it’s in.
            merge '**/LICENSE.txt'
            merge '**/NOTICE.txt'
            merge '**/notice.txt'
            merge '**/license.txt'
            merge '**/NOTICE'
            merge '**/LICENSE'
            merge '**/notice'
            merge '**/license'
            merge '**/LGPL2.1'
            // This will exclude any README files, regardless of the dir or the file type.
            exclude '**/README.*'
    }
    

    This answer is better than using pickFirst because that method only picks the first license it finds and disregards all the rest, kinda rendering it useless in this case.

    So in short, use the merge method to include all those licenses from those kickass open source libraries you’ve been using.

    More info on Gradle PackagingOptions.

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