1、如果你的项目没有其他第三方包的话,那么进行混淆很简单,只需要将project.properties文件夹下面的注释解开就行,一点区别在于:如果您是2.3之前的sdk版本,那么就用这个proguard.config=proguard.cfg
如果是之后的则为:proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt(当然视您生成项目时候该文件具体生成情况所定)。
2、如果有第三方lib包的话,则混淆时需要注意了,以下是常用的一些lib包的混淆配置:
1)友盟
-keep class com.umeng*.**{*;}
-keep public class * extends com.umeng.**
-keepclassmembers class * {
public <init>(org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class com.hx.wwy.R$*{
public static final int *;
}
-dontwarn com.umeng*.**
-dontwarn com.umeng.**
如果加了友盟的消息推送,需要另外加上如下命令:
-keep class com.umeng.message.* {
public <fields>;
public <methods>;
}
-keep class com.umeng.message.protobuffer.* {
public <fields>;
public <methods>;
}
-keep class com.squareup.wire.* {
public <fields>;
public <methods>;
}
-keep class com.umeng.message.local.* {
public <fields>;
public <methods>;
}
-keep class org.android.agoo.impl.*{
public <fields>;
public <methods>;
}
2)百度
-keep class com.baidu.** {*;}
-keep class vi.com.gdi.bgl.android.**{*;}
-dontwarn com.baidu.**
3)support.v4的
#-keep class android.support.v4.** {*; }
-keep interface android.support.v4.app.**{*;}
-dontwarn android.support.v4.**
4)gson
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.* { *; }
-keep class com.google.gson.examples.android.model.* { *; }
-keep class com.google.gson.* { *;}
-dontwarn com.google.gson.**
5)环信
-keep class com.easemob.** {*;}-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
-keep class com.hx.wwy.util.SmileUtils {*;}
-dontwarn com.easemob.**
#2.0.9后加入语音通话功能,如需使用此功能的api
-dontwarn ch.imvs.**
-dontwarn org.slf4j.**
-keep class org.ice4j.** {*;}
-keep class net.java.sip.** {*;}
-keep class org.webrtc.voiceengine.** {*;}
-keep class org.bitlet.** {*;}
-keep class org.slf4j.** {*;}
-keep class ch.imvs.** {*;}
6)mob分享
-keep class com.mob.tools.**{*;}
-keep class android.net.http.SslError
-keep class android.webkit.**{*;}
-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class com.alipay.share.sdk.**{*;}
-keep class **.R$* {
*;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class com.jauker.widget.**{*;}
-keep class cn.sharesdk.wechat.friends.**{*;}
-keep class cn.sharesdk.wechat.utils.**{*;}
-keep class cn.sharesdk.tencent.qzone.**{*;}
-keep class cn.sharesdk.tencent.moments.**{*;}
-keep class cn.sharesdk.tencent.qq.**{*;}
-keep class cn.sharesdk.framework.**{*;}
-keep class cn.sharesdk.onekeyshare.**{*;}
7)nostra13 第三方图片处理库
-keep class com.nostra13.universalimageloader.** { *; }
-dontwarn com.nostra13.universalimageloader.**
#-keep class com.nostra13.universalimageloader.core.assist.**{*;}
#-keep class com.nostra13.universalimageloader.core.**{*;}
#-keep class com.nostra13.universalimageloader.cache.disc.**{*;}
#-keep class com.nostra13.universalimageloader.cache.memory.**{*;}
#-keep class com.nostra13.universalimageloader.utils.**{*;}
8)Xutil 的
#-keep class com.lidroid.xutils.**{*;}
9)Android本身的
-keep public class * extends android.app.Fragment
-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.app.View
-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 * extends android.support.v4.**
-keep public class com.android.vending.licensing.ILicensingService
-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);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
下面粘贴一下我以前项目代码混淆的处理。
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes InnerClasses,LineNumberTable
-libraryjars libs/android-support-v4.jar
-libraryjars libs/badgeview.jar
-libraryjars libs/baidumapapi_v3_2_0.jar
-libraryjars libs/com.umeng.message.lib_v2.0.0.jar
-libraryjars libs/umeng-analytics-v5.4.2.jar
-libraryjars libs/easemobchat_2.2.1.jar
-libraryjars libs/fitScreen.jar
-libraryjars libs/gson-2.2.4.jar
-libraryjars libs/MobTools.jar
-libraryjars libs/ShareSDK-Core-2.6.0.jar
-libraryjars libs/ShareSDK-QQ-2.6.0.jar
-libraryjars libs/ShareSDK-QZone-2.6.0.jar
-libraryjars libs/ShareSDK-Wechat-2.6.0.jar
-libraryjars libs/ShareSDK-Wechat-Core-2.6.0.jar
-libraryjars libs/ShareSDK-Wechat-Moments-2.6.0.jar
-libraryjars libs/universal-image-loader-1.9.1.jar
-libraryjars libs/xUtils-2.6.10.jar
-keep public class * extends android.app.Fragment
-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.app.View
-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 * extends android.support.v4.**
-keep public class com.android.vending.licensing.ILicensingService
-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);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keep class com.baidu.** {*;}
-keep class vi.com.gdi.bgl.android.**{*;}
-dontwarn com.baidu.**
#-keep class android.support.v4.** {*; }
-keep interface android.support.v4.app.**{*;}
-dontwarn android.support.v4.**
-keep class com.umeng*.**{*;}
-keep public class * extends com.umeng.**
-keepclassmembers class * {
public <init>(org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class com.hx.wwy.R$*{
public static final int *;
}
-dontwarn com.umeng*.**
-dontwarn com.umeng.**
-keep class com.easemob.** {*;}
-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
-keep class com.hx.wwy.util.SmileUtils {*;}
-dontwarn com.easemob.**
#2.0.9后加入语音通话功能,如需使用此功能的api
-dontwarn ch.imvs.**
-dontwarn org.slf4j.**
-keep class org.ice4j.** {*;}
-keep class net.java.sip.** {*;}
-keep class org.webrtc.voiceengine.** {*;}
-keep class org.bitlet.** {*;}
-keep class org.slf4j.** {*;}
-keep class ch.imvs.** {*;}
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.* { *; }
-keep class com.google.gson.examples.android.model.* { *; }
-keep class com.google.gson.* { *;}
-dontwarn com.google.gson.**
#-keep class com.lidroid.xutils.**{*;}
-keep class com.mob.tools.**{*;}
-keep class android.net.http.SslError
-keep class android.webkit.**{*;}
-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class com.alipay.share.sdk.**{*;}
-keep class **.R$* {
*;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class com.jauker.widget.**{*;}
-keep class cn.sharesdk.wechat.friends.**{*;}
-keep class cn.sharesdk.wechat.utils.**{*;}
-keep class cn.sharesdk.tencent.qzone.**{*;}
-keep class cn.sharesdk.tencent.moments.**{*;}
-keep class cn.sharesdk.tencent.qq.**{*;}
-keep class cn.sharesdk.framework.**{*;}
-keep class cn.sharesdk.onekeyshare.**{*;}
-keep class com.nostra13.universalimageloader.** { *; }
-dontwarn com.nostra13.universalimageloader.**
#-keep class com.nostra13.universalimageloader.core.assist.**{*;}
#-keep class com.nostra13.universalimageloader.core.**{*;}
#-keep class com.nostra13.universalimageloader.cache.disc.**{*;}
#-keep class com.nostra13.universalimageloader.cache.memory.**{*;}
#-keep class com.nostra13.universalimageloader.utils.**{*;}
-keep class com.hx.wwy.service.**{*;}
#-keep class com.hx.wwy.asynctask.**{*;}
-keep class com.hx.wwy.bean.**{*;}
#-keep class com.hx.wwy.adapter.**{*;}
-keep class com.hx.wwy.widget.**{*;}
#-keep class com.hx.wwy.util.**{*;}
-keep class com.hx.wwy.fragment.**{*;}
#-keep class com.hx.wwy.dao.**{*;}
-keep class com.hx.wwy.putfile.**{*;}
-keep class com.hx.wwy.wxapi.**{*;}