Android 库项目:混淆并保留资源
我想使用 Proguard 来编译我的 Android 项目以及一些额外的 Android 库项目。事实上,大部分代码和资源都位于这些库中。
我已将“proguard.config=proguard.cfg”行添加到主项目的project.properties中,我已配置cfg文件(-libraryjars ..\libs)。然后-右键单击,Android工具->导出签名的申请包。 ADT 编译了要发布的项目,但应用程序在第一次启动时崩溃了:正如我从日志中读到的,这是因为错误的资源指针。
我反编译了项目,发现了非常奇怪的事情:如果我在库中声明资源,那么它的资源指针就会变成0。
当我将“proguard.config=proguard.cfg”行添加到project.properties中时,问题并没有消失我所有的 Android 库项目。
有什么解决办法吗?
编辑:查看 proguard.cfg 的片段:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !
-printusage unused.txt
-optimizationpasses 2
-printmapping mapping.txt
# -overloadaggressively
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-libraryjars ..\libs
I want to compile with Proguard my Android project with some additional Android Library Projects. In fact, most of code and resources lie in these libraries.
I've added line "proguard.config=proguard.cfg" into project.properties of main project, I've configured cfg-file (-libraryjars ..\libs). Then - right click, Android Tools -> Export Signed Application Package. ADT compiled project for release but app crashed at the first launch: as I read from log, it was because of wrong resource pointer.
I've decompiled project and found out very strange thing: if I declare resource in the library, then resource pointer on it becomes 0.
Problem didn't disappear when I add line "proguard.config=proguard.cfg" into project.properties of all of my Android Library Project.
Any solutions?
Edit: look at fragment of proguard.cfg:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !
-printusage unused.txt
-optimizationpasses 2
-printmapping mapping.txt
# -overloadaggressively
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-libraryjars ..\libs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定您拥有最新的工具吗?喜欢 Eclipse Indigo、ADT v16.0.1 和 proguard 4.7 吗?在更新到最新工具之前我也遇到了问题。
Are you sure you have the latest tools? Like Eclipse Indigo, ADT v16.0.1 and proguard 4.7? I also had issues before updating to the latest tools.
如何包含/引用您的 Android 库项目?如果我没看错的话,你将它们添加为罐子吗?如果是这样,您确实可能会在使用图书馆项目提供的资源时遇到一些麻烦。
如果我是对的,请尝试:
使用“项目设置”并在其中添加您的库项目。不要为此使用一些导出的罐子。 Android 库项目的工作方式与普通 java 库的工作方式有很大不同。
How do you include/reference to your Android Library Projects? If I read it correctly, you add them as a jar? If so you really might got some trouble with the resources provided by the library projects.
If I am right, try that:
Use the Project Settings and add your library projects there. Do not use some exported jars for that. The way an Android Library Project works is way different than a normal java library works.