222 lines
8.9 KiB
Prolog
222 lines
8.9 KiB
Prolog
# ============================================================
|
||
# baselibrary 库模块 consumer-rules.pro
|
||
# 传递给依赖本库的 App 模块的混淆规则(必须存在!)
|
||
# build.gradle -> defaultConfig -> consumerProguardFiles "consumer-rules.pro"
|
||
# ============================================================
|
||
|
||
# 保留注解、泛型签名、运行时注解(网络层反射核心属性)
|
||
-keepattributes Signature,*Annotation*,AnnotationDefault,RuntimeVisibleAnnotations,RuntimeVisibleParameterAnnotations,InnerClasses,EnclosingMethod
|
||
|
||
# ==============================
|
||
# BaseNetworkApi:反射获取实际 Service 类型的泛型基类(核心!)
|
||
# 修复:java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.network.base.BaseNetworkApi { *; }
|
||
-keep class * extends com.abbidot.baselibrary.network.base.BaseNetworkApi { *; }
|
||
# 关键:保留所有继承 BaseNetworkApi 的子类的父类泛型参数声明(防止 R8 擦除 actualTypeArguments)
|
||
-keep,allowshrinking class * extends com.abbidot.baselibrary.network.base.BaseNetworkApi {
|
||
<init>(...);
|
||
}
|
||
-keepclassmembers class * extends com.abbidot.baselibrary.network.base.BaseNetworkApi {
|
||
<fields>;
|
||
<methods>;
|
||
}
|
||
# 保留 IService 接口
|
||
-keep interface com.abbidot.baselibrary.network.base.IService { *; }
|
||
|
||
# ==============================
|
||
# BaseResponse<T>:所有网络响应的泛型基类(Gson 反序列化依赖)
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.network.base.BaseResponse { *; }
|
||
# 保持所有 BaseResponse 子类的泛型签名不被擦除
|
||
-keepclassmembers class * extends com.abbidot.baselibrary.network.base.BaseResponse {
|
||
<fields>;
|
||
<init>(...);
|
||
}
|
||
|
||
# ==============================
|
||
# Gson TypeAdapter:StringNullAdapter / DoubleDefault0Adapter
|
||
# 通过 GsonBuilder.registerTypeAdapter 反射实例化
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.network.interceptor.StringNullAdapter { *; }
|
||
-keep class com.abbidot.baselibrary.network.interceptor.DoubleDefault0Adapter { *; }
|
||
-keepclassmembers class com.abbidot.baselibrary.network.interceptor.StringNullAdapter {
|
||
<init>();
|
||
}
|
||
-keepclassmembers class com.abbidot.baselibrary.network.interceptor.DoubleDefault0Adapter {
|
||
<init>();
|
||
}
|
||
|
||
# ==============================
|
||
# OkHttp Interceptor:CommonRequestInterceptor / CommonResponseInterceptor
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.network.interceptor.CommonRequestInterceptor { *; }
|
||
-keep class com.abbidot.baselibrary.network.interceptor.CommonResponseInterceptor { *; }
|
||
-keepclassmembers class com.abbidot.baselibrary.network.interceptor.CommonRequestInterceptor {
|
||
<init>();
|
||
}
|
||
-keepclassmembers class com.abbidot.baselibrary.network.interceptor.CommonResponseInterceptor {
|
||
<init>();
|
||
}
|
||
|
||
# ==============================
|
||
# 异常类(反射抛出时需保留类名)
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.network.exception.** { *; }
|
||
|
||
# ==============================
|
||
# Retrofit 3.0 / OkHttp 5(Kotlin-first 新版本,额外加固规则)
|
||
# ==============================
|
||
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
|
||
-keep,allowobfuscation,allowshrinking class retrofit2.Response
|
||
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
|
||
-keep,allowobfuscation,allowshrinking class retrofit2.KotlinExtensions
|
||
# 所有带 Retrofit http 注解的接口方法必须保留(用于动态代理反射)
|
||
-if interface * { @retrofit2.http.* <methods>; }
|
||
-keep,allowobfuscation interface * { <methods>; }
|
||
# OkHttp 5 消除内部平台警告
|
||
-dontwarn okhttp3.internal.platform.**
|
||
-dontwarn org.conscrypt.**
|
||
-dontwarn org.bouncycastle.**
|
||
-dontwarn org.openjsse.**
|
||
-dontwarn org.codehaus.mojo.animal_sniffer.*
|
||
|
||
# ==============================
|
||
# Gson(配合 Retrofit 3.0 converter-gson 使用)
|
||
# ==============================
|
||
-keep class com.google.gson.** { *; }
|
||
-dontwarn com.google.gson.**
|
||
# TypeToken 匿名内部类的泛型签名必须保留
|
||
-keep class com.google.gson.reflect.TypeToken { *; }
|
||
-keep class * extends com.google.gson.reflect.TypeToken { *; }
|
||
-keepclassmembers class * extends com.google.gson.reflect.TypeToken {
|
||
<init>(...);
|
||
java.lang.reflect.Type getType();
|
||
}
|
||
-keepnames class com.google.gson.internal.** { *; }
|
||
# SerializedName / Expose 注解字段保留
|
||
-keepclassmembers,allowshrinking,allowobfuscation class * {
|
||
@com.google.gson.annotations.SerializedName <fields>;
|
||
@com.google.gson.annotations.Expose <fields>;
|
||
}
|
||
|
||
# ==============================
|
||
# 自定义 View / LayoutInflater 反射构造函数保留
|
||
# 所有通过 XML inflate 的自定义 View 必须保留 (Context, AttributeSet) 构造
|
||
# ==============================
|
||
-keepclassmembers class * extends android.view.View {
|
||
public <init>(android.content.Context, android.util.AttributeSet);
|
||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||
public <init>(android.content.Context, android.util.AttributeSet, int, int);
|
||
void set*(***);
|
||
*** get*();
|
||
}
|
||
-keepclassmembers class * extends android.view.ViewGroup {
|
||
public <init>(android.content.Context, android.util.AttributeSet);
|
||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||
public <init>(android.content.Context, android.util.AttributeSet, int, int);
|
||
}
|
||
# baselibrary 内部自定义 View
|
||
-keep class com.abbidot.baselibrary.widget.** { *; }
|
||
-keepclassmembers class com.abbidot.baselibrary.widget.** {
|
||
public <init>(...);
|
||
<fields>;
|
||
<methods>;
|
||
}
|
||
|
||
# ==============================
|
||
# 常量类(EventName/ConState/MMKVKey 等):伴生对象 const val 虽被 inline,但类名/成员名保留方便反射查找
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.constant.** { *; }
|
||
-keepclassmembers class com.abbidot.baselibrary.constant.** {
|
||
<fields>;
|
||
<methods>;
|
||
public static final *;
|
||
}
|
||
|
||
# ==============================
|
||
# XEventBus 事件总线(核心:发送/接收/观察者包装类必须保留)
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.eventbus.** { *; }
|
||
-keep class com.abbidot.baselibrary.eventbus.core.** { *; }
|
||
-keepclassmembers class * {
|
||
@com.abbidot.baselibrary.constant.EventName <fields>;
|
||
}
|
||
|
||
# ==============================
|
||
# BaseRecyclerAdapter 列表适配器和 ViewHolder
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.list.** { *; }
|
||
-keepclassmembers class com.abbidot.baselibrary.list.** {
|
||
public <init>(...);
|
||
<fields>;
|
||
<methods>;
|
||
}
|
||
|
||
# ==============================
|
||
# baselibrary.util:AppUtils/LogUtil/MMKVUtil/Utils(双重保险:app 模块里也写了一份)
|
||
# ==============================
|
||
-keep class com.abbidot.baselibrary.util.** { *; }
|
||
-keepclassmembers class com.abbidot.baselibrary.util.** {
|
||
public <init>(...);
|
||
<fields>;
|
||
<methods>;
|
||
}
|
||
|
||
# ==============================
|
||
# Parcelable / kotlinx-parcelize:跨模块 Intent 传值必备
|
||
# ==============================
|
||
# 注意:@Parcelize 是 SOURCE/BINARY 级编译期注解,运行时不存在,禁止写 -keep @kotlinx.parcelize.Parcelize
|
||
-keep class * implements android.os.Parcelable { *; }
|
||
-keepclassmembers class * implements android.os.Parcelable {
|
||
public static final android.os.Parcelable$Creator *;
|
||
public static final android.os.Parcelable$ClassLoaderCreator *;
|
||
<init>(android.os.Parcel);
|
||
<init>(android.os.Parcel, java.lang.ClassLoader);
|
||
void writeToParcel(android.os.Parcel, int);
|
||
int describeContents();
|
||
}
|
||
# kotlin-parcelize 运行时生成的内部辅助类($Creator、$Parceler)
|
||
-keep class **$Creator { *; }
|
||
-keep class **$Parceler { *; }
|
||
-keepclassmembers class **$Creator { <fields>; <methods>; }
|
||
-keepclassmembers class **$Parceler { <fields>; <methods>; }
|
||
-dontwarn kotlinx.parcelize.**
|
||
|
||
# ==============================
|
||
# ViewModel:跨模块 by viewModels() 反射创建
|
||
# ==============================
|
||
-keep class * extends androidx.lifecycle.ViewModel { *; }
|
||
-keepclassmembers class * extends androidx.lifecycle.ViewModel {
|
||
public <init>(...);
|
||
protected <init>(...);
|
||
<fields>;
|
||
<methods>;
|
||
}
|
||
|
||
# ==============================
|
||
# Kotlin 协程 / suspend 函数:Continuation 签名不被擦除
|
||
# ==============================
|
||
-keep class kotlin.coroutines.Continuation { *; }
|
||
-keep class kotlin.coroutines.intrinsics.** { *; }
|
||
-keep class kotlinx.coroutines.** { *; }
|
||
-dontwarn kotlinx.coroutines.**
|
||
-dontwarn kotlin.coroutines.**
|
||
|
||
# ==============================
|
||
# Kotlin 伴生对象 / 单例 INSTANCE:EventName.Companion / ConState.Companion 等
|
||
# ==============================
|
||
-keepclassmembers class **$Companion {
|
||
<fields>;
|
||
<methods>;
|
||
public static final *;
|
||
static *;
|
||
}
|
||
-keep class **$Companion { *; }
|
||
-keepclassmembers class * {
|
||
public static final ** INSTANCE;
|
||
public static final ** Companion;
|
||
public static ** getINSTANCE();
|
||
public static ** getCompanion();
|
||
}
|