Android Proguard 重复定义
我正在尝试将第 3 方库 (JmDNS) 添加到我的 Android 项目中。
我在基本项目目录下创建了一个文件夹“libs”,并将 jar 文件放入该目录中。
当我尝试使用 Ant(ant 版本)构建项目时,我收到了 JmDNS jar 文件中每个类的“重复定义”通知。
....
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Canceler]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.DNSStateTask]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Prober]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Renewer]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.package-info]
[proguard] Note: duplicate definition of library class [javax.jmdns.package-info]
[proguard] Note: there were 357 duplicate class definitions.
构建也会失败,并出现以下错误:
BUILD FAILED
/path/Tools/ant-android-scala/build-scala.xml:183: Can't write [/path/bin/projectname-debug-shrinked.jar] (Can't read [/path/projectname/libs/jmdns.jar(;;;;!META-INF/MANIFEST.MF,!library.properties)] (Duplicate zip entry [jmdns.jar:javax/jmdns/JmDNS$Delegate.class]))
我已确保 jar 文件仅包含一次,并且没有其他方法可以在项目中的任何位置包含重复的源文件。
否则为什么 Proguard 会抱怨重复的定义呢?
I'm attempting to add a 3rd party library (JmDNS) to my Android project.
I created a folder 'libs' under the base project directory, and dropped the jar file in the directory.
When I attempt to build he project using Ant (ant release), I receive a 'duplicate definition' notices for what appears to be each class in the JmDNS jar file.
....
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Canceler]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.DNSStateTask]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Prober]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Renewer]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.package-info]
[proguard] Note: duplicate definition of library class [javax.jmdns.package-info]
[proguard] Note: there were 357 duplicate class definitions.
The build also fails with the following error:
BUILD FAILED
/path/Tools/ant-android-scala/build-scala.xml:183: Can't write [/path/bin/projectname-debug-shrinked.jar] (Can't read [/path/projectname/libs/jmdns.jar(;;;;!META-INF/MANIFEST.MF,!library.properties)] (Duplicate zip entry [jmdns.jar:javax/jmdns/JmDNS$Delegate.class]))
I've made sure that the jar file is only included once, and there is no other way that I am including duplicate source files anywhere in the project.
Why else would Proguard complain about duplicate definitions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将第 3 方库移动到另一个目录(在我的例子中为“lib”)来修复此问题。然后添加
到proguard.cfg文件中。
如果第 3 方磅包含在“libs”文件夹中,则它们会被处理两次。
Fixed this by moving the 3rd party libraries to another directory, in my case 'lib'. Then added
to the proguard.cfg file.
If the 3rd party lbs are included in the 'libs' folder, then they are processed twice.
在当前的 progaurd 版本中,无需指定 injar。默认情况下会处理它。这可能是由于以下原因造成的
- 1) 某些引用的库中存在重复的 jar 文件。
解决方案 - 将其从应用程序中删除并使其成为参考库
2) 可能是由于应用程序 gradle 文件和引用库 gradle 文件之间的 gradle 版本不同。使其相同。
解决方案 - 将 gradle 文件编辑为引用的库/项目的 gradle 文件之一。查看两个项目的类路径是相同的。
依赖项{
类路径'com.android.tools.build:gradle:1.3.0'
我遇到了这两个问题
,纠正了它并且它起作用了。
In current progaurd version there is no need to specify injars. It is handled by default. This could be due to the following reasons-
1) duplicate jar files in some referenced libraries.
Solution - Removed it from the application and let it be reference library
2) Could be due to different gradle versions between your application gradle file and referenced library gradle file. Make it same.
Solution - Edit the gradle file to one of the referenced library's/Project's gradle file. See the classpath is same for both projects.
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
I had both these problems, rectified it and it worked.