Proguard笔记

最近比较闲,重新整理了一下Proguard,主要是为了方便以后开发,简单记录下。

Proguard配置步骤:

step1
项目中添加proguard.cfg 文件
这里写图片描述

并写入内容如下:

# 声明不输出那些未找到的引用和一些错误,但续混淆
-dontwarn 

# 指定执行几次优化,默认情况下,只执行一次优化
-optimizationpasses 5

#指定在混淆的时候不使用大小写混用的类名
-dontusemixedcaseclassnames

#指定读取引用库文件的时候不跳过非public类
-dontskipnonpubliclibraryclasses

#不优化输入的类文件 
-dontoptimize

#声明在处理过程中输出更多信息。添加这项配置之后,如果处理过程中出现异常,会输出整个StackTrace而不是一条简单的异常说明。
-verbose

#指定混淆是采用的算法,后面的参数是一个过滤器
#这个过滤器是谷歌推荐的算法,一般不做更改
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*



-keep enum com.facebook.**
#---------------------
#指定受保护的属性,不被混淆,可以有一个或者多个
#---------------------
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
#跟踪异常信息
-keepattributes SourceFile,LineNumberTable

-keep public interface com.facebook.**
-keep public interface com.tencent.**
-keep public interface com.umeng.socialize.**
-keep public interface com.umeng.socialize.sensor.**
-keep public interface com.umeng.scrshot.**



-keep public class com.umeng.socialize.* {*;}
-keep public class javax.**
-keep public class android.webkit.**

-keep class com.facebook.**
-keep class com.umeng.scrshot.**
-keep public class com.tencent.** {*;}
-keep class com.umeng.socialize.sensor.**

-keep class com.tencent.mm.sdk.modelmsg.WXMediaMessage {*;}

-keep class com.tencent.mm.sdk.modelmsg.** implements com.tencent.mm.sdk.modelmsg.WXMediaMessage$IMediaObject {*;}

-keep class im.yixin.sdk.api.YXMessage {*;}
-keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}

-keep public class [com.cmcc.enterprise].R$*{
    public static final int *;
}


-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 * extends android.database.ContentObserver
-keep public class com.android.vending.licensing.ILicensingService

-keep public class android.util.Xml.** { *;}
-keep public interface android.util.Xml.** { *;}
-keep public class * extends android.support.v4.app.FragmentActivity
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.TabActivity
-keep public class * extends android.app.Application
-keep public class android.telephony.TelephonyManager
-keep public class * extends android.os.AsyncTask
#-keep class com.cmcc.numberportable.utils.** { *;}
#-keep class com.cmcc.numberportable.util.** { *;}
#-keep class com.cmcc.numberportable.dialog.** { *;}
-keepattributes Signature

#-keep class com.gmcc.issac_json.json.parse.** { *;}

-keep class org.apache.http.** {
    <fields>;
    <methods>;
}

-keep class org.xmlpull.** {
    <fields>;
    <methods>;
}
-keep class android.io.** { *;}

-keep class com.htjf.openability.** {
    <fields>;
    <methods>;
}


-keep class com.htjf.openability.smsfilter.SmsFilterCtrlSync {
    <fields>;
    <methods>;
}
-keepclassmembers class * {
    public <init>(org.json.JSONObject);
}

-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);
}

#保留Parcelable序列化类不被混淆
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}


-keep class com.google.** {
    <fields>;
    <methods>;
}

#保留Serializable序列化的类不被混淆
-keepclassmembers class * extends java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keep class sun.misc.Unsafe {
    <fields>;
    <methods>;
}

-keep class com.gmcc.issac_globaldht_ndk.bean.** {
    <fields>;
    <methods>;
}

-keep class com.gmcc.issac_globaldht_ndk.https.HttpsUtil {
    <fields>;
    <methods>;
}

-keep class com.cmcc.numberportable.bean.** { *;}
-keep class com.cmcc.numberportable.utils.PhoneReceiver {
    <fields>;
    <methods>;
}

-keep class android.os.ServiceManager {
    <fields>;
    <methods>;
}

-keep class com.android.internal.telephony.ITelephony {
    <fields>;
    <methods>;
}
-keep class java.lang.reflect.Method {
    <fields>;
    <methods>;
}



#--------------------------------------------
#-libraryjars classpaath 
#指定要处理的应用程序jar,war,ear和目录所需要的程序库文件 
#----------------------------------------------

-libraryjars libs/armeabi/libglobalDhtNDKJni.so  
-libraryjars libs/armeabi/libKeyStoreJni.so
-libraryjars libs/armeabi/libOAFileCrypt.so
-libraryjars libs/armeabi/libmatchcorev2.so  
-libraryjars libs/armeabi/libOANetCrypt.so
-libraryjars libs/armeabi/libRuleCryption.so

-libraryjars libs/DoubleSimSDK_V0.2.jar
-libraryjars libs/GetThreads.jar
-libraryjars libs/glide-3.6.0.jar
-libraryjars libs/littlec_SDK_android_IM_V1.3.1.jar
-libraryjars libs/SmsFilter.jar
-libraryjars libs/yznl_common.jar
-libraryjars libs/yznl_dht.jar


step2
在project.properties 文件中添加:

proguard.config=proguard.cfg

step3
打包即可。

Proguard 效果

Daxiong_dv_v0.0.3_20161206_1.apk 打包时没有进行混淆打包的,
Daxiong_dv_v0.0.3_20161206_2.apk 打包时则是执行了混淆工作。
可以看到混淆过后的apk比未混淆过的apk占用空间更小。

这里写图片描述

再看下反编译查看混淆过的apk,包名是经过混淆的,非常难读,activity 在proguard声明忽略混淆,故未被混淆。

这里写图片描述

再看下某个activity,成员变量被混淆了,无很难读懂代码。

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值