使用 Ant 和 Proguard 编译 Android 应用程序时出现问题
我有一个 Android 应用程序,它由不同的模块组成。 Main 模块使用一些库,例如 Google 的 GSON 或 v4.support.package。具有正确 proguard.cfg 的自定义构建脚本也将构建它。 现在我必须集成另一个“Android-Library”,它使用部分相同的库(GSON support.v4)。除了得到很多像这样的笔记
注意:程序类 [com.google.gson.Gson] 的重复定义
我还得到一些注释,例如
[proguard] 注意:com.google.gson.UnsafeAllocator:找不到动态引用的类 sun.misc.Unsafe
[proguard] 注意:配置引用了未知类“sun.misc.Unsafe”
,我觉得很奇怪,因为我我的 Proguard.cfg 中有一些“保留”,特别是为此:
-keepattributes 签名,注释
-保留类 com.google.gson.** {*;}
-保留类 sun.misc.Unsafe { *; }
在我的项目中运行良好,无需引用其中的模块库。 我使用最新的 SDK 和工具,并向模块库添加了一个自定义的 proguard.cfg,它在模块库本身上运行良好(如果以独立模式构建)。 在我看来,构建并不依赖于库项目内的自定义 proguard.cfg。任何关于尝试什么的想法都非常感谢
I have an Android App which consists on different modules. The Main module is using some libs like Google's GSON or the v4.support.package. A custom build script with the right proguard.cfg will build it, too.
Now I must integrate another "Android-Library" which uses partly the same libs (GSON support.v4). Beside from getting a lot of Notes like
Note: duplicate definition of program class [com.google.gson.Gson]
I get also some Notes like
[proguard] Note: com.google.gson.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
[proguard] Note: the configuration refers to the unknown class 'sun.misc.Unsafe'
that I find strange cause i have some 'keeps' in my Proguard.cfg especially for that:
-keepattributes Signature, Annotation
-keep class com.google.gson.** {*;}
-keep class sun.misc.Unsafe { *; }
which works well on my project without referencing the module-library inside it.
I'm on the Latest SDK and Tools, and added a custom proguard.cfg to the module-library, which works well on the module-lib itself (if build in standalone-mode).
It seems to me, that the build is not depending on custom proguard.cfg inside library-projects. Any idea on what to try highly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于自己找到了解决方案:
使用最后的 Android 工具 (16),每个 Android 库都会首先自行编译。
因此,当 lib 没有“标准”构建并定义了一些自定义构建脚本(包括 proguard --keeps),并且此 --keeps 是在同一项目上定义的(不包括 Android SDK 类,因为它们未编译)时,它会导致一个混淆器错误。
解决方案是从库中删除 proguard 并将 --keeps 复制到主应用程序中
I finally found a solution for it myself:
with the last Android Tools (16), every Android-Library gets compiled on its own first.
So when the lib has not a "standart" build and defines some custom build script including proguard --keeps, and this --keeps are defined on the same Project (excluding Android SDK classes, as thei're not compiled) it leads to an proguard error.
The Solution was do remove proguard out of the lib and copy the --keeps inside the main App