修改混淆规则

This commit is contained in:
Lindong 2026-01-27 16:13:17 +08:00
parent da258f69f6
commit 75f8111c13
1 changed files with 113 additions and 232 deletions

331
app/proguard-rules.pro vendored
View File

@ -1,51 +1,40 @@
# Add project specific ProGuard rules here. # ==============================================================================
# You can control the set of applied configuration files using the # 基础配置 (Basic Configuration)
# proguardFiles setting in build.gradle. # ==============================================================================
# # 代码优化次数
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# ---------------------------------- 基础配置 ----------------------------------
# 代码优化次数通常设为5
-optimizationpasses 5 -optimizationpasses 5
# 不使用混合大小写类名 # 不使用混合大小写类名
-dontusemixedcaseclassnames -dontusemixedcaseclassnames
# 不忽略非公共库类 # 不忽略非公共库类
-dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclasses
# 不进行预校验Android不需要可加快速度
-dontpreverify
# 打印混淆详情 # 打印混淆详情
-verbose -verbose
# 忽略警告 # 忽略警告
-ignorewarnings -ignorewarnings
# 不进行预校验
-dontpreverify
# ---------------------------------- 保留重要属性 ---------------------------------- # ==============================================================================
# 保留泛型签名重要避免JSON解析等类型转换错误 # 属性保留 (Attributes)
# ==============================================================================
# 保留泛型签名避免JSON解析Kotlin反射等问题
-keepattributes Signature -keepattributes Signature
# 保留注解(如@Keep, @SerializedName等 # 保留注解
-keepattributes *Annotation* -keepattributes *Annotation*
# 保留异常信息 # 保留异常信息
-keepattributes Exceptions -keepattributes Exceptions
# 保留源代码文件名和行号(便于崩溃日志分析) # 保留内部类信息
-keepattributes InnerClasses
# 保留封闭方法信息
-keepattributes EnclosingMethod
# 保留源文件和行号用于Crashlytics堆栈追踪
-keepattributes SourceFile,LineNumberTable -keepattributes SourceFile,LineNumberTable
# 如果需要隐藏源文件名,取消注释下面这行
#-renamesourcefileattribute SourceFile
# ---------------------------------- 保留Android基本组件 ---------------------------------- # ==============================================================================
# 保留四大组件及其子类 # Android 组件 (Android Components)
# ==============================================================================
-keep public class * extends android.app.Activity -keep public class * extends android.app.Activity
-keep public class * extends android.app.Application -keep public class * extends android.app.Application
-keep public class * extends android.app.Service -keep public class * extends android.app.Service
@ -53,18 +42,25 @@
-keep public class * extends android.content.ContentProvider -keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference -keep public class * extends android.preference.Preference
-keep public class * extends android.view.View
# 保持 Native 方法不被混淆 # 保持 Native 方法
-keepclasseswithmembernames class * { -keepclasseswithmembernames class * {
native <methods>; native <methods>;
} }
# 保持 Parcelable 序列化类不被混淆 # 保持自定义 View 的构造方法
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# 保持 Parcelable
-keep class * implements android.os.Parcelable { -keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *; public static final android.os.Parcelable$Creator *;
} }
# 保持 Serializable 序列化的类成员不被混淆 # 保持 Serializable
-keepclassmembers class * implements java.io.Serializable { -keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID; static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields; private static final java.io.ObjectStreamField[] serialPersistentFields;
@ -74,250 +70,135 @@
java.lang.Object readResolve(); java.lang.Object readResolve();
} }
# 保持自定义 View 的构造方法不被混淆(用于 XML 布局) # 保持枚举
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# 保持枚举类不被混淆
-keepclassmembers enum * { -keepclassmembers enum * {
public static **[] values(); public static **[] values();
public static ** valueOf(java.lang.String); public static ** valueOf(java.lang.String);
} }
# 保持由 JSON 转换的 Bean 类(或者你的数据模型类)不被混淆 # 保持 R 文件资源引用
-keep class com.gamedog.vididin.beans.** { *; }
-keep class com.gamedog.vididin.router.** { *; }
# 保留R文件中的静态字段保证资源反射能正常工作
-keepclassmembers class **.R$* { -keepclassmembers class **.R$* {
public static <fields>; public static <fields>;
public static final int *;
} }
# gson # ==============================================================================
-keep class com.google.gson.** { *; } # Kotlin Coroutines
-keep class sun.misc.Unsafe { *; } # ==============================================================================
-keep class com.google.gson.stream.** { *; } -keep class kotlinx.coroutines.** { *; }
# 明确保护被@SerializedName注解的字段 -keepclassmembers class kotlinx.coroutines.** {
volatile <fields>;
}
# 如果使用 AtomicFU
-dontwarn java.util.concurrent.atomic.Atomic*
# ==============================================================================
# Kotlin Serialization
# ==============================================================================
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,allowobfuscation,allowshrinking class kotlinx.serialization.* { *; }
-keep class * implements kotlinx.serialization.KSerializer { *; }
-keepclassmembers class * { -keepclassmembers class * {
@com.google.gson.annotations.SerializedName <fields>; @kotlinx.serialization.Serializable <init>(...);
@kotlinx.serialization.Serializable <fields>;
} }
-keep @kotlinx.serialization.Serializable class * { *; }
# ==============================================================================
#okhttp # 项目特定 (Project Specific)
# OkHttp3 # ==============================================================================
-dontwarn okhttp3.** # 实体类/Bean (防止 JSON 解析失败)
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okio.**
# Retrofit2
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature, Exceptions
#butter knife
# Butter Knife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
# ---------------------------------- 核心排除Bean/Model类防止JSON解析失败 ----------------------------------
# 规则:保护所有你定义的用于JSON序列化/反序列化的数据模型类JavaBean/POJO)不被混淆
# 替换 `com.yourpackage.model` 为你的数据模型类所在的实际包名
# 这将保护该包(及其子包)下所有类的类名字段名和方法名不被更改
-keep class com.gamedog.vididin.beans.** { *; } -keep class com.gamedog.vididin.beans.** { *; }
-keep class com.gamedog.vididin.manager.taskbeans.** { *; }
# 任务配置Bean
-keep class com.gamedog.vididin.main.fragments.task.** { *; }
# 路由相关
-keep class com.gamedog.vididin.router.** { *; }
# App 入口
-keep class com.viddin.videos.free.VidiDinApp { *; } -keep class com.viddin.videos.free.VidiDinApp { *; }
# ==============================================================================
# 第三方库 (Third Party Libraries)
# ==============================================================================
# 如果模型类实现了Serializable接口建议额外保留序列化版本UID和特定方法 # ----------------- Hilt / Dagger -----------------
-keepclassmembers class com.yourpackage.model.** 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();
}
# --------------------------------------------------
# Hilt 核心规则
# --------------------------------------------------
# 保留 Hilt 的注解处理器生成的类
-keep class dagger.hilt.internal.aggregatedroot.** { *; } -keep class dagger.hilt.internal.aggregatedroot.** { *; }
-keep class hilt_aggregated_deps.** { *; } -keep class hilt_aggregated_deps.** { *; }
# 保留使用 @AndroidEntryPoint 注解的 Android 组件Activity, Fragment, View, Service, BroadcastReceiver
-keep class * extends android.app.Application { @dagger.hilt.android.AndroidEntryPoint <init>(); } -keep class * extends android.app.Application { @dagger.hilt.android.AndroidEntryPoint <init>(); }
-keepclasseswithmembers class * { @dagger.hilt.android.AndroidEntryPoint <fields>; } -keepclasseswithmembers class * { @dagger.hilt.android.AndroidEntryPoint <fields>; }
-keepclasseswithmembers class * { @dagger.hilt.android.AndroidEntryPoint <methods>; } -keepclasseswithmembers class * { @dagger.hilt.android.AndroidEntryPoint <methods>; }
# 保留 Hilt 模块类,确保依赖提供逻辑不被混淆
-keep @dagger.Module class * -keep @dagger.Module class *
-keep @dagger.hilt.InstallIn class * -keep @dagger.hilt.InstallIn class *
# 保留 Hilt 入口点EntryPoint相关的类
-keep @dagger.hilt.EntryPoint class * -keep @dagger.hilt.EntryPoint class *
-keepclassmembers @dagger.hilt.EntryPoint class * { *; } -keepclassmembers @dagger.hilt.EntryPoint class * { *; }
# 保留 Hilt 生成的组件Component相关类
-keep @dagger.hilt.components.SingletonComponent class * -keep @dagger.hilt.components.SingletonComponent class *
-keepclassmembers @dagger.hilt.components.SingletonComponent class * { *; } -keepclassmembers @dagger.hilt.components.SingletonComponent class * { *; }
# 保留 Hilt 处理器生成的工厂类
-keep class * extends dagger.internal.Binding { *; } -keep class * extends dagger.internal.Binding { *; }
-keep class * extends dagger.internal.Factory { *; } -keep class * extends dagger.internal.Factory { *; }
-keep class * implements dagger.MembersInjector { *; } -keep class * implements dagger.MembersInjector { *; }
-keep class * implements dagger.Lazy { *; } -keep class * implements dagger.Lazy { *; }
# 保留泛型信息,这对依赖注入很关键 # ----------------- Gson -----------------
-keepattributes Signature, InnerClasses, EnclosingMethod -keep class com.google.gson.** { *; }
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keepclassmembers class * {
@com.google.gson.annotations.SerializedName <fields>;
}
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# 保留注解信息Hilt 严重依赖注解) # ----------------- OkHttp3 -----------------
-keepattributes *Annotation* -dontwarn okhttp3.**
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okio.**
# ----------------- Retrofit2 -----------------
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
# ----------------- Glide -----------------
##############加密混淆###########
########腾讯X5内核浏览器中的的代码不被混淆#####
-keep class com.tencent.** {*;}
########RSA中的代码不被混淆
-keep class Decoder.** {*;}
-keep class org.bouncycastle.** {*;}
################Glide加载图片添加混淆
-keep public class * implements com.bumptech.glide.module.GlideModule -keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES; **[] $VALUES;
public *; public *;
} }
######## glide类库 -keep class com.bumptech.glide.** { *; }
######## com.github.bumptech.glide:okhttp3-integration:1.4.0@aar中的代码不被混淆 # Glide Transformations
######## jp.wasabeef:glide-transformations:2.0.1 不被混淆
-keep class com.bumptech.** {*;}
-keep class jp.wasabeef.glide.** { *; } -keep class jp.wasabeef.glide.** { *; }
########## 保证类库Image 中导入的jar包不被混淆 # 相关依赖
-keep class com.davemorrissey.** { *; } -keep class com.davemorrissey.** { *; }
-keep class com.filippudak.** { *; } -keep class com.filippudak.** { *; }
-keep class am.util.** {*;}
-keep class com.blankj.** {*;}
#########################################################第三方的配置结束####################### # ----------------- Lottie -----------------
-keep class com.airbnb.lottie.** { *; }
#==================gson && protobuf========================== # ----------------- Room -----------------
-dontwarn com.google.** -dontwarn androidx.room.paging.**
-keep class com.google.gson.** {*;}
-keep class com.google.protobuf.** {*;}
#ProGuard 混淆 # ----------------- Tencent X5 / Security -----------------
-keep class com.tencent.** { *; }
# keep住源文件以及行号 -keep class Decoder.** { *; }
-keepattributes SourceFile,LineNumberTable -keep class org.bouncycastle.** { *; }
-keepattributes Signature
-dontwarn com.jcraft.jzlib.**
-keep class com.jcraft.jzlib.** { *;}
-dontwarn sun.misc.**
-keep class sun.misc.** { *;}
# ----------------- Alibaba FastJson -----------------
-dontwarn com.alibaba.fastjson.** -dontwarn com.alibaba.fastjson.**
-keep class com.alibaba.fastjson.** { *; } -keep class com.alibaba.fastjson.** { *; }
-dontwarn sun.security.** # ----------------- JZlib / Apache / Others -----------------
-keep class sun.security.** { *; } -dontwarn com.jcraft.jzlib.**
-keep class com.jcraft.jzlib.** { *; }
-dontwarn com.google.**
-keep class com.google.** { *;}
-dontwarn com.avos.**
-keep class com.avos.** { *;}
-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient
-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslEr
-dontwarn android.webkit.WebViewClient
-dontwarn android.support.**
-dontwarn org.apache.** -dontwarn org.apache.**
-keep class org.apache.** { *; } -keep class org.apache.** { *; }
-dontwarn org.jivesoftware.smack.**
-keep class org.jivesoftware.smack.** { *;}
-dontwarn com.loopj.** -dontwarn com.loopj.**
-keep class com.loopj.** { *; } -keep class com.loopj.** { *; }
-dontwarn org.jivesoftware.smack.**
-dontwarn org.xbill.** -dontwarn org.xbill.**
-keep class org.xbill.** { *; } -keep class org.xbill.** { *; }
-keepattributes *Annotation* # ==============================================================================
# 结束 (End)
# ==============================================================================
# Gson
#gson
#如果用用到Gson解析包的直接添加下面这几行就能成功混淆不然会报错
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# Application classes that will be serialized/deserialized over Gson
##---------------End: proguard configuration for Gson ----------
#基础混淆添加配置
-keepclassmembers class **.R$* {
public static <fields>;
public static final int *;
}
-keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆
public void *(android.view.View);
}
# bean目录
-keep class com.viddin.videos.free.VidiDinApp** {*;}
-keep class com.gamedog.vididin.beans.** {*;}
-keep class com.gamedog.vididin.manager.taskbeans.** {*;}
-keep class com.gamedog.vididin.router.** {*;}