** 下面是我找问题的时候遇见的不错的文章**
文章引用自:sirai
proguard-rules.pro 混淆(自己测过了,除了EventBus)
#避免混淆Android基本组件,下面是兼容性比较高的规则:
-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 class android.device.** { *; }
#避免混淆所有native的方法,涉及到C、C++
-keepclasseswithmembernames class * {
native <methods>;
}
#避免混淆属性动画兼容库
-dontwarn com.nineoldandroids.*
-keep class com.nineoldandroids.** { *;}
#避免混淆js相关的接口
-keepattributes *JavascriptInterface*
#===================android 兼容包,androidx start============================
#不提示V4包下错误警告
-dontwarn android.support.v4.**
#保持下面的V4兼容包的类不被混淆
-keep class android.support.v4.**{*;}
#androidx 混淆
-keep class com.google.android.material.** {*;}
-keep class androidx.** {*;}
-keep public class * extends androidx.**
-keep interface androidx.** {*;}
-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**
-dontwarn androidx.**
# No static method asAttributeSet(Lorg/xmlpull/v1/a;)Landroid/util/AttributeSet;
-dontwarn org.xmlpull.v1.XmlPullParser
-dontwarn org.xmlpull.v1.XmlSerializer
-keep class org.xmlpull.v1.* {*;}
#===================android 兼容包,androidx end============================
#===================类 start============================
#避免混淆枚举类
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#避免混淆注解类
-dontwarn android.annotation
-keepattributes *Annotation*
#避免混淆内部类
-keepattributes InnerClasses
#不混淆泛型
-keepattributes Signature
#避免混淆自定义控件类的get/set方法和构造函数
-keep public class * extends android.view.View{
*** get*();
void set*(***);
public <init>(android.content.Context);
public <init>(android.content.Context,android.util.AttributeSet);
public <init>(android.content.Context,android.util.AttributeSet,int);
}
#===================类 end============================
#==================bean解析相关 start==================
-keep public class * implements java.io.Serializable {*;}
#使用GSON、fastjson等框架时,所写的JSON对象类不混淆,否则无法将JSON解析成对应的对象
-keepclassmembers class * {
public <init>(org.json.JSONObject);
}
# Gson 混淆
-keep class com.google.gson.stream.** { *; }
-keepattributes EnclosingMethod
# bean类不被混淆
-keep class com.***.***.entity.** { *;}
#不混淆Parcelable和它的实现子类,还有Creator成员变量
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#不混淆Serializable和它的实现子类、其成员变量
-keepclassmembers class * implements 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();
}
# ==================bean解析相关 end==================
# ==================bugly start==================
-dontwarn com.tencent.bugly.**
-keep public interface com.tencent.**
-keep public class com.tencent.** {*;}
-keep public class com.tencent.bugly.**{*;}
# ==================bugly end====================
# ==================EventBus start=================
-keep class org.greenrobot.** {*;}
-keep class de.greenrobot.** {*;}
-keepclassmembers class ** {
public void onEvent*(**);
void onEvent*(**);
}
# ==================EventBus end===================
# ==================okhttp start===================
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.** { *;}
-dontwarn okio.**
-keep class okio.**{*;}
-keep interface okio.**{*;}
# OkHttp3
-dontwarn okhttp3.logging.**
-keep class okhttp3.internal.**{*;}
-dontwarn okio.**
# ==================okhttp end=====================
# ==================Retrofit start=====================
# Retrofit 混淆
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
## Platform calls Class.forName on types which do not exist on Android to determine platform.
#-dontnote retrofit2.Platform
## Platform used when running on RoboVM on iOS. Will not be used at runtime.
#-dontnote retrofit2.Platform$IOS$MainThreadExecutor
## Platform used when running on Java 8 VMs. Will not be used at runtime.
#-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keepattributes *Annotation*
#retrofit2 混淆
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-keep class sun.misc.Unsafe { *; }
# ==================Retrofit end=====================
# ==================Rxjava/RxAndroid start=====================
#避免混淆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;
}
# ==================Rxjava/RxAndroid end=====================
# ==================butterknife start=====================
#butterknife 混淆
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
# ==================butterknife end=====================
## ==================picasso框架 start===============
#-keep class com.parse.*{ *; }
#-dontwarn com.parse.**
#-dontwarn com.squareup.picasso.**
#-keepclasseswithmembernames class * {
# native <methods>;
#}
## ==================picasso end====================
# ==================bugly start=====================
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
# tinker混淆规则
-dontwarn com.tencent.tinker.**
-keep class com.tencent.tinker.** { *; }
-keep class android.support.**{*;}
# ==================bugly end=====================
# ==================自定义混淆 start=====================
# 在加入bugly的热更新后,需要设置like,因为这个like会被APP的构造方法作为delegateClassName参数传
#入(全名传入,所以这个类需要不能被混淆)
-keep class com.*.*.MyApplicationLike{*;}
# ==================自定义混淆 end=====================
网友评论