JavaME的程序要打成Jar包提交,由于移动的限制,Jar的file size越小越好。Proguard无疑是最受青睐的混淆器之一。 混淆打包的时候,经常遇到这样的问题:如何将keep指令保留的class放到default package中?搜寻了很久也没有找到答案,都想利用Proguard的src自己来写个小工具了,又仔细搜了一边help forum,终于看到了 解决方案 。 Quote: Keeping a class name means keeping its fully qualified name. You could try creating a mapping file with the name that you want, and feeding it into ProGuard with -applymapping. In ProGuard 4.0 beta, you can specify -keep,allowobfuscation instead of just -keep. If you use -printmapping, you can then find the obfuscated name in the mapping file. Eric. 可以先用keep执行一次obfuscate,将映射结果用printmapping打印出来,保存为proguard.map文件,再修改其中MIDlet类型的映射,如: com.jlazy.MyMIDlet -> MyMIDlet 然后,在keep选项之后加一个参数allowobfuscation: -keep,allowobfuscation public class * extends javax.microedition.midlet.MIDlet 并在progard中指定使用map文件执行repackage: -applymapping 'proguard.map' 这样就搞定了,所有的class都放到了default package中。 这个解决方法必须要使用 Proguard 4.0 beta 以上版本。而且由于要在第一次生成映射文件,多做了一步,感觉还可以再改进。如果Eric没有时间加入这个feature的话,打算自己写一个并集成到ant脚本中。