Android Proguard 混淆的 ANT 构建
任何人都可以分享 Android 的示例/简单混淆 ANT 任务吗?假设我有完整的 APK,我只需要通过 *class hru Proguard,然后准备 *.dex 来构建 APK
Can anyone share with sample/simple obfuscation ANT task for Android? Provided that I do have complete APK and I need just pass *class hru Proguard and then prepare *.dex to build APK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了解决方案:
更新完成build.xml
此 ANT 任务必须添加到 Eclipse 的构建器(属性/构建器)任务中,位于 Java 构建器之后、Android 包构建器之前。
按“Build All”(最好在 Eclipse 菜单中关闭“自动构建”检查)
I have found solution:
UPDATE complete build.xml
This ANT task has to be added to Eclipse's builders (Properties/Builders) tasks after Java builder and before Android package builder.
Press "Build All" (it's better to off Automatic Build check in Eclipse menu)
Android 构建过程首先将 Java 源文件 (.java) 编译为 Java 类文件 (.class),然后将这些类文件转换为 Dalvik 代码 (classes.dex),最后将此 Dalvik 代码打包到 APK 文件中。
ProGuard 读取和写入 Java 类文件,因此必须在编译步骤和转换步骤之间将其插入到此管道中。它本身不会读取或写入 Dalvik 代码,因此无法处理 APK 文件。
ProGuard 上的 Android SDK 文档 讨论了如何在 Android 的 Ant 构建中启用混淆步骤 - 9.简而言之,您必须在文件 default.properties 中添加一行“proguard.config=proguard.cfg”,然后运行“ant release”。
The Android build process first compiles Java source files (.java) to Java class files (.class), then converts these class files into Dalvik code (classes.dex), and finally packages this Dalvik code in an APK file.
ProGuard reads and writes Java class files, so it has to be inserted into this pipeline between the compilation step and the conversion step. It doesn't read or write Dalvik code itself, so it can't work on the APK file.
The Android SDK documentation on ProGuard discusses how to enable the obfuscation step in the Ant build for android-9. In short, you have to add a line "proguard.config=proguard.cfg" to the file default.properties, and then run "ant release".
注意:barmaley的回复是2011年的,似乎对Android SDK Tools版本8或10有效。
我尝试使用Android SDK Tools版本18.1.1来适应这个解决方案,但一直失败错误:
taskdef class com.android.ant.SetupTask 找不到
最终,我所做的是:
这创建了一个新的 build.xml,它与当前的 SDK 工具兼容,并且似乎自动化了巴马利的回复中描述了很多手工工作。
之后,我能够运行
ant release
,它负责构建和混淆开箱即用的结果 .apk 文件。为了通过 ant 自动进行混淆,您需要:
ant.properties
文件并用适当的 key.store 参数填充它(请参阅 此回复了解详细信息)。Attention: barmaley's reply is from year 2011, and seem to be valid for Android SDK Tools version either 8 or 10.
I tried adapting this solution using Android SDK Tools version 18.1.1, but kept failing on the error:
taskdef class com.android.ant.SetupTask cannot be found
Eventually, what I did was this:
This created a fresh build.xml which is compliant with the current SDK Tools, and seem to automate a lot of the manual work that is described in barmaley's reply.
After that I was able to run
ant release
, which took care of building and obfuscating the result .apk file out of the box.In order to automate obfuscation via ant, you'll need to:
ant.properties
file and fill it with the appropriate key.store params (see this SO reply for details).proGuard 混淆过程需要 .class 文件,因此您无法在 IDE 构建 (.java) 之前或之后(.dex 打包)启动 Ant。
看一下这篇文章,其中解释了如何在全局 Ant 构建中添加 proGuard 步骤:
http://www.androidengineer.com/2010/07/optimizing-obfuscating-and-shrinking.html
如果你确实想使用IDEA构建,你可以尝试以下操作。
抱歉,我没有附加 apktool 和 dexjar 的链接,但由于我是新手,我无法发布多个超链接。
The proGuard obfuscation process needs .class files so you can't launch an Ant before IDE build (.java) or after (.dex packed).
Have a look on this post where it's explained how add the proGuard step in your global Ant build:
http://www.androidengineer.com/2010/07/optimizing-obfuscating-and-shrinking.html
If you really want to use the IDEA build, you can try the following.
Sorry that I don't attach you the links of apktool and dexjar but as I'm newbie I can't post more than one hyperlink.