开源中文网

您的位置: 首页 > Android开发 > 正文

android 混淆文件proguard.cfg详解

来源: csdn博客  作者: yujian_bing


-injars  androidtest.jar【jar包所在地址】
-outjars  out【输出地址】
-libraryjars    'D:\Android-sdk-windows\platforms\android-9\android.jar' 【引用的库的jar,用于解析injars所指定的jar类】
-optimizationpasses 5
-dontusemixedcaseclassnames 【混淆时不会产生形形色色的类名 】
-dontskipnonpubliclibraryclasses 【指定不去忽略非公共的库类。 】
-dontpreverify 【不预校验】
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 【优化】
-keep public class * extends android.app.Activity  【不进行混淆保持原样】
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public abstract interface com.asqw.android.Listener{
public protected <methods>;  【所有方法不进行混淆】
}
-keep public class com.asqw.android{
public void Start(Java.lang.String); 【对该方法不进行混淆】
}
-keepclasseswithmembernames class * { 【保护指定的类和类的成员的名称,如果所有指定的类成员出席(在压缩步骤之后)】
native <methods>;
}
-keepclasseswithmembers class * { 【保护指定的类和类的成员,但条件是所有指定的类和类成员是要存在。】
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {【保护指定类的成员,如果此类受到保护他们会保护的更好 】
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {【保护指定的类文件和类的成员】
public static final android.os.Parcelable$Creator *;
}

我在导出项目时报这种异常提示:
12-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] Proguard returned with error code 1. See console
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] Note: there were 2 duplicate class definitions.
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]
Warning: there were 9 instances of library classes depending on program classes.
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]          You must avoid such dependencies, since the program classes will
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity]          be processed, while the library classes will remain unchanged.
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] java.io.IOException: Please correct the above warnings first.
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] at proguard.Initializer.execute(Initializer.java:321)
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] at proguard.ProGuard.initialize(ProGuard.java:211)
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] at proguard.ProGuard.execute(ProGuard.java:86)
[2012-11-08 17:37:03 - com.zrwt.android.unicom.ui.LoginActivity] at proguard.ProGuard.main(ProGuard.java:492)

找了半天才发现,我的工程中只有proguard-project.txt和project.properties文件,没有proguard.cfg,default.properties这两个文件,
并且我把proguard.config=proguard.cfg这句代码给加在了project.properties的文件中了。
所以才出现了如上错误。后来,我把那两文件给删了,从别的项目中考了default.properties和proguard.cfg的文件,
并把proguard.config=proguard.cfg这句话写在了default.properties文件中,混淆代码导出终于成功。大功告成!

加入第三方jar包之后常出现的几个异常:
proguard returned with error code 1.See console
情况1:
Proguard returned with error code 1. See console
Error: C:/Documents (系统找不到指定文件)
后来发现是因为将整个工程放到了桌面上,而桌面的目录是C:/Documents and Settings/Administrator/桌面,
在这里面有空格,而proguard进行发编译的时候是不允许有空格的
如果换了正确路径还不好用的话,直接删除proguard就好了
注意:SDK和程序路径最好不要有空格符
情况2:
Proguard returned with error code 1. See console
异常:
java.lang.ArrayIndexOutOfBoundsException
解决办法:将proguard.cfg中的"-dontpreverify"改成“-dontoptimize”



我把项目中生成的proguard文件夹(此时文件夹是空的)删掉,然后再重新运行项目,就OK 了。
情况3:
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0] Proguard returned with error code 1. See console

[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0] java.io.IOException: Can't read [proguard.ClassPathEntry@106082] (No such file or directory)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.InputReader.readInput(InputReader.java:230)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.InputReader.readInput(InputReader.java:200)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.InputReader.readInput(InputReader.java:178)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.InputReader.execute(InputReader.java:100)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.ProGuard.readInput(ProGuard.java:195)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.ProGuard.execute(ProGuard.java:78)
[2011-10-21 13:22:32 - ZMKSMarket_Build_v1.0]
at proguard.ProGuard.main(ProGuard.java:499)
抛出这样的异常的原因是第三方jar的引用路径不对,没有找到这个需要忽略混淆的jar包。

Tags:文件
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明