Android代码混淆

1.基本指令区


# 代码混淆压缩比,在0~7之间,默认为5,一般不做修改
-optimizationpasses 5

# 混合时不使用大小写混合,混合后的类名为小写
-dontusemixedcaseclassnames

# 指定不去忽略非公共库的类
-dontskipnonpubliclibraryclasses

# 指定不去忽略非公共库的类成员
-dontskipnonpubliclibraryclassmembers

# 不进行优化,建议使用此选项,
-dontoptimize

# 不做预校验,preverify是proguard的四个步骤之一,Android不需要preverify 能够加快混淆速度。
-dontpreverify

# 使我们的项目混淆后产生映射文件包含有类名->混淆后类名的映射关系
-verbose

# 使用printmapping指定映射文件的名称
-printmapping proguardMapping.txt

# 屏蔽警告
-ignorewarnings

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

# 保留Annotation不混淆
-keepattributes *Annotation*

# 避免混淆泛型
-keepattributes Signature

# 抛出异常时保留代码行号
-keepattributes SourceFile,LineNumberTable

2.AndroidX混淆

# 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.**

2.自己项目中定义的实体类

# 自己项目中定义的实体类
-keep class com.XXX.bean.** { *; }
-keep class com.XXX.widget.** { *; }
-keep class com.XXX.utils.** { *; }
-keep class com.XXX.base.** { *; }

3.第三方框架类

#第三方框架
# ButterKnife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

# EventBus
-keepclassmembers class ** {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    <init>(java.lang.Throwable);
}

# PictureSelector
-keep class com.luck.picture.lib.** { *; }
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
-dontwarn org.codehaus.mojo.animal_sniffer.*

# zxing
-keep class com.google.zxing.{ *;}
-dontwarn com.google.zxing.**
-dontwarn cn.bingoogolapple.**
-keep class cn.bingoogolapple.*{ *;}

# Glide
-dontwarn com.bumptech.glide.**
-keep class com.bumptech.glide.**{*;}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

# Gson
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { <fields>; }
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

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

# Retrofit
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
-keepattributes Exceptions
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }

# 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;
}
-dontnote rx.internal.util.PlatformDependent


# 微信支付
-dontwarn com.tencent.mm.**
-dontwarn com.tencent.wxop.stat.**
-keep class com.tencent.mm.** {*;}
-keep class com.tencent.wxop.stat.**{*;}

# 支付宝钱包
-dontwarn com.alipay.**
-dontwarn HttpUtils.HttpFetcher
-dontwarn com.ta.utdid2.**
-dontwarn com.ut.device.**
-keep class com.alipay.android.app.IAlixPay{*;}
-keep class com.alipay.android.app.IAlixPay$Stub{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{*;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}
-keep class com.alipay.mobilesecuritysdk.*
-keep class com.ut.*

# banner
-dontwarn com.youth.banner.**
-keep class com.youth.banner.**{*;}

# loading
-keep class com.wang.avi.** { *; }
-keep class com.wang.avi.indicators.** { *; }

# JPTabBar
-keep class com.jpeng.** {*;}

# SmartRefreshLayout
-keep class com.scwang.** {*;}

# 万能适配器 BaseRecyclerViewAdapterHelper
-keep class com.chad.library.adapter.** {
*;
}
-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
-keep public class * extends com.chad.library.adapter.base.BaseViewHolder
-keepclassmembers public class * extends com.chad.library.adapter.base.BaseViewHolder {
     <init>(android.view.View);
}

#友盟
-keep class com.umeng.**{*;}
#您如果集成了U-APM产品可以加入该混淆
-keep class com.uc.**{*;}
-keepclassmembers class*{
public<init>(org.json.JSONObject);
}
-keepclassmembers enum*{
publicstatic**[] values();
publicstatic** valueOf(java.lang.String);
}

# 屏幕适配
-keep class me.jessyan.autosize.** { *; }
-keep interface me.jessyan.autosize.** { *; }
# 版本更新-dontwarn com.king.app.updater.**-keep class com.king.app.updater.**{ *;}-keep class * extends com.king.app.updater.**{ *;}-keep class * implements com.king.app.updater.**{ *;}-keepattributes InnerClasses-dontwarn com.king.app.dialog.**-keep class com.king.app.dialog.**{ *;}
#shareSDK-keep class cn.sharesdk.**{*;}-keep class com.sina.**{*;}-keep class com.mob.**{*;}-keep class com.bytedance.**{*;}-dontwarn cn.sharesdk.**-dontwarn com.sina.**-dontwarn com.mob.**-keep class androidx.recyclerview.widget.**{*;}-keep class androidx.viewpager2.widget.**{*;}

posted @ 2022-10-19 13:44  い果粒橙ぺ  阅读(107)  评论(0编辑  收藏  举报