Android Proguard警告:无法写入资源(重复的zip条目)

19

我启用了Proguard并出现了以下错误:

Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-io-2.4.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-io-2.4.jar:META-INF/NOTICE.txt])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-collections-3.2.1.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-collections-3.2.1.jar:META-INF/NOTICE.txt])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [joda-time-2.7-no-tzdb.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [joda-time-2.7-no-tzdb.jar:META-INF/NOTICE.txt])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-primitives-1.0.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/services/javax.annotation.processing.Processor] (Duplicate zip entry [icepick-processor-2.3.6.jar:META-INF/services/javax.annotation.processing.Processor])
Warning:can't write resource [.readme] (Duplicate zip entry [classes.jar:.readme])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-lang-2.6.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-lang-2.6.jar:META-INF/NOTICE.txt])

这是什么意思? 我应该像这样排除一些东西吗?
configurations {
    all*.exclude group: 'commons-logging', module: 'commons-logging'
}
3个回答

30

您正在使用具有重复文件的库,这是gradle中的一个错误,为解决此问题,请在您的项目build.gradle中使用以下代码:

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

1
这并没有帮助。已尝试使用“packagingOptions ”来排除 'META-INF / DEPENDENCIES','META-INF / NOTICE','META-INF / LICENSE','META-INF / LICENSE.txt'和'META-INF / NOTICE.txt',但这也没有帮助。 - Andrew
对我有用!谢谢!我喜欢我的干净构建。 :) - alenz316
添加这些行后,请发布logcat并发布您的build.gradle。 - Santiago
由于某种原因,“排除‘.readme’”未能消除警告。 - Jared Burrows
5
packagingOptions 在 package* 任务中应用,而上面的警告来自 proguard,在 release 构建类型中打包之前运行。请参阅 http://proguard.sourceforge.net/manual/troubleshooting.html#duplicatezipentry。 - Joe Bowbeer

1

来自Proguard手册:

警告:无法写入资源...重复的zip条目

您的输入JAR包包含多个具有相同名称的资源文件。 ProGuard会像往常一样继续复制资源文件,跳过任何已经使用过名称的文件。但是,警告可能是某些问题的指示,因此建议删除重复项。一种方便的方法是在输入JAR包上指定过滤器。没有选项可以关闭这些警告。

标准的Android构建过程会自动为您指定输入JAR包。可能没有简单的方法可用于过滤它们以消除这些警告。您可以手动从输入和库中删除重复的资源文件。


但是我无法手动删除它们,因为它们在库中,所以似乎没有办法做到这一点? - Daniel Gomez Rico

0

2
是啊,但是我们的想法是尽可能避免警告的出现! - Daniel Gomez Rico

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接