若项目中没有proguard.cfg文件,手动添加
新建文本,输入以下代码
-dontwarn //若项目中导入了第三方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 com.android.vending.licensing.ILicensingService -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }
重命名文本为proguard.cfg
将该文件复制到项目中,与AndroidManifest.xml文件在同一层
打开project.properties文件,添加以下内容
proguard.config=proguard.cfg
保存,右击项目名->Android-Tools->Export Unsigned Application Package
生成项目apk,混淆完成
若该过程中报 java.io.IOException: Please correct the above warnings这个错误,可能是忘记在proguard.cfg中添加 -dontwarn 添加后重试。