Android 代码混淆(常用框架混淆配置)


1、android 平台自带的排除混淆项

指定代码的压缩级别
-optimizationpasses 5
包明不混合大小写
-dontusemixedcaseclassnames
不去忽略非公共的库类
-dontskipnonpubliclibraryclasses
 #优化  不优化输入的类文件
-dontoptimize
 #预校验
-dontpreverify
 #混淆时是否记录日志
-verbose
 # 混淆时所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
保护注解
-keepattributes *Annotation*
 保持哪些类不被混淆
-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.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
如果有引用v4包可以添加下面这行
-keep public class * extends android.support.v4.app.Fragment
忽略警告
-ignorewarning          
-keep public class * extends android.support.** #如果有引用v4或者v7包,需添加
-keepattributes Signature        #不混淆泛型
-keepnames class * implements java.io.Serializable #不混淆Serializable
-keep public class com.cxd.cxd4android.R$*{
public static final int *;
}
-keepclasseswithmembernames class * {  # 保持 native 方法不被混淆
    native ;
}
-keepclasseswithmembers class * {      # 保持自定义控件类不被混淆
    public (android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {      # 保持自定义控件类不被混淆
    public (android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆
    public void *(android.view.View);
}
-keep public class * extends android.app.Activity{
    public ;
    public ;
}
-keepclassmembers enum * {             # 保持枚举 enum 类不被混淆
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {         # 保持 Parcelable 不被混淆
    public static final android.os.Parcelable$Creator *;
}

2、常用第三方框架混淆的排除项

sharesdk混淆

-keep class android.net.http.SslError
-keep class android.webkit.*{;}
-keep class cn.sharesdk.*{;}
-keep class com.sina.*{;}
-keep class m.framework.*{;}

Gson混淆配置

-keepattributes Annotation
-keep class sun.misc.Unsafe { *; }
-keep class com.idea.fifaalarmclock.entity.*
-keep class com.google.gson.stream.* { ; }

butterknife混淆配置

-keep class butterknife.* { ; }
-dontwarn butterknife.internal.**
-keep class *$$ViewBinder { ; }
-keepclasseswithmembernames class * {
@butterknife.* ;
}
-keepclasseswithmembernames class * {
@butterknife.* ;
}

Retrofit混淆配置

-dontwarn retrofit2.**
-keep class retrofit2.* { ; }
-keepattributes Signature
-keepattributes Exceptions

RxJava RxAndroid混淆配置

-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.ArrayQueue*Field {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}

OkHttp3混淆

-dontwarn com.squareup.okhttp3.**
-keep class com.squareup.okhttp3.* { ;}
-dontwarn okio.**

Eventbus混淆

-keepattributes Annotation
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe ;
}
-keep enum org.greenrobot.eventbus.ThreadMode {
*;
}
# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
(java.lang.Throwable);
}

你可能感兴趣的:(Android知识,studio项目,知识总结)