收集一些Android常用混淆代碼

反編譯過別人的jar或者apk的小伙伴肯定會發(fā)現(xiàn)大量的類名,方法名,變量名等等,都被替換成了a,b,c,d之類的字母,造成難以閱讀。代碼混淆是保障我們代碼安全的一種有力手段,但是并不是所有代碼都需要被混淆的,不恰當?shù)幕煜赡軐е马椖繜o法正常運行。下面收集一些開發(fā)當中常用的一些三方依賴的混淆代碼。

1.ButterKnife

# Retain generated class which implement Unbinder.
-keep public class * implements butterknife.Unbinder { public <init>(...); }

# Prevent obfuscation of types which use ButterKnife annotations since the simple name
# is used to reflectively look up the generated ViewBinding.
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }

2.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
-keep class sun.misc.Unsafe { *; }

#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# 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

##---------------End: proguard configuration for Gson ----------

注意上面代碼中的-keep class com.google.gson.examples.android.model.** { *; }僅僅是一個示例,照抄過去是沒有作用的。這里我們需要避免混淆的是需要經(jīng)過Gson序列化的實體類,開發(fā)過程中我們通常將實體類放在同一個包下,這里直接寫包路徑即可。

3.Glide

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
     **[] $VALUES;
     public *;
}
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

4.支付寶支付

-libraryjars libs/alipaySDK-20150602.jar
 
-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 *;}

第一行中alipaySDK-20150602.jar為jar包名稱,注意替換為自己使用的jar包。

5.微信支付

-keep class com.tencent.mm.sdk.** {*;}

6.EventBus

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

7.xUtils3

-keepattributes Signature,*Annotation*
-keep public class org.xutils.** {
       public protected *;
}
-keep public interface org.xutils.** {
       public protected *;
}
-keepclassmembers class * extends org.xutils.** {
       public protected *;
}
-keepclassmembers @org.xutils.db.annotation.* class * {*;}
-keepclassmembers @org.xutils.http.annotation.* class * {*;}
-keepclassmembers class * {
       @org.xutils.view.annotation.Event <methods>;
}

8.個推

-dontwarn com.igexin.**
-keep class com.igexin.**{*;}

8.Retrofit2.1.0

# 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

9.高德地圖

    3D 地圖
    -keep   class com.amap.api.maps.**{*;} 
    -keep   class com.autonavi.amap.mapcore.*{*;} 
    -keep   class com.amap.api.trace.**{*;}

     定位
    -keep class com.amap.api.location.**{*;}
    -keep class com.amap.api.fence.**{*;}
    -keep class com.autonavi.aps.amapapi.model.**{*;}

    搜索
    -keep   class com.amap.api.services.**{*;}

    2D地圖
    -keep class com.amap.api.maps2d.**{*;}
    -keep class com.amap.api.mapcore2d.**{*;}

    導航
    -keep class com.amap.api.navi.**{*;}
    -keep class com.autonavi.**{*;}

10.Bugly

-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}

有任何疑問,歡迎加群討論:261386924

文章同步更新于微信公眾號: 秉心說 , 專注 Java 、 Android 原創(chuàng)知識分享,LeetCode 題解,歡迎關(guān)注!

qrcode_for_gh_de090eed4f33_258.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,030評論 25 709
  • 在離職之際,也沒有啥事可以做,就自己搗騰下代碼混淆,言歸正傳。 為了防止自己的勞動成果被別人竊取,混淆代碼能有效防...
    Orz013閱讀 1,084評論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評論 19 139
  • 在Android Studio當中混淆APK實在是太簡單了,借助SDK中自帶的Proguard工具,只需要修改ap...
    自由翱翔de錘錘閱讀 2,618評論 1 2
  • 當我拿到《別再說你沒時間》這本書時,心里是欣喜的,至少我看到它的第一眼我不討厭它。它是一本比一般書籍略小,書...
    小熊_5849閱讀 445評論 2 7

友情鏈接更多精彩內(nèi)容