Android Studio code obfuscation - third-party jar obfuscation summary (continuous update)

Preface

Android has many excellent third-party open source jar packages. We often use a lot of jar packages in our projects, but we often forget to confuse third-party jar packages when it comes to release, which will bring us a lot of trouble in development. All of these will summarize some popular third-party jar packages confusion ways here to facilitate everyone's development. This article will continue to be updated. If you have other confusing ways to use jar packages, you can also inform me, so that you can better provide you with a more complete example.
This blog is published synchronously XueLong's blog

Common third-party open source jar packages

Ranking is non-sequential (alphabetical)

Android-gif-drawable link

-keep public class pl.droidsonroids.gif.GifIOException{<init>(int);}
-keep class pl.droidsonroids.gif.GifInfoHandle{<init>(long,int,int,int);}

Android-Universal-Image-Loader link

#Universal Image Loader
-keep class com.nostra13.universalimageloader.** { *; }
-keepattributes Signature

ButterKnife link

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keep class **$$ViewInjector
-keepclasseswithmembernames class * {    
   @butterknife.* <fields>;
}
-keepclasseswithmembernames class * {    
   @butterknife.* <methods>;
}

Bugly link

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

EventBus link

-keepclassmembers class ** {
    public void onEvent*(***);
}

# Only required if you use AsyncExecutor
-keepclassmembers class * extends de.greenrobot.event.util.ThrowableFailureEvent {
    public <init>(java.lang.Throwable);
}

# Don't warn for missing support classes
-dontwarn de.greenrobot.event.util.*$Support
-dontwarn de.greenrobot.event.util.*$SupportManagerFragment

Fabric Twitter Kit link

-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* *;
}

Fastjson link

-dontwarn com.alibaba.fastjson.**
-keepattributes Signature
-keepattributes *Annotation*

Glide link

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

# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

Gson link

# 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

Letter SDK link

-keep class com.easemob.** {*;}
-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
-dontwarn  com.easemob.**
# No need to add the following keep after 2.0.9
#-keep class org.xbill.DNS.** {*;}
# In addition, reflections are used when sending expressions in demo, and keep SmileUtils is required.
-keep class com.easemob.chatuidemo.utils.SmileUtils {*;}
# Note the package name above. If you copy this class under your own project, such as under com.example.utils, you should write it as follows (actually, you need to remove #)
#-keep class com.example.utils.SmileUtils {*;}
# If you use easeui libraries, you need to write this
-keep class com.easemob.easeui.utils.EaseSmileUtils {*;}
# After 2.0.9, add voice call function. If you need to use the api of this function, add the following keep
-dontwarn ch.imvs.**
-dontwarn org.slf4j.**
-keep class org.ice4j.** {*;}
-keep class net.java.sip.** {*;}
-keep class org.webrtc.voiceengine.** {*;}
-keep class org.bitlet.** {*;}
-keep class org.slf4j.** {*;}
-keep class ch.imvs.** {*;}

LitePal link

-keep class org.litepal.** {
    *;
}

-keep class * extends org.litepal.crud.DataSupport {
    *;
}

Okhttp link

-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

OkhttpUtils link

#okhttputils
-dontwarn com.zhy.http.**
-keep class com.zhy.http.**{*;}

#okhttp
-dontwarn okhttp3.**
-keep class okhttp3.**{*;}

#okio
-dontwarn okio.**
-keep class okio.**{*;}

Picasso link

-dontwarn com.squareup.okhttp.**

Retrofit2 link

-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

RxJava link

-keep class rx.schedulers.Schedulers {
    public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
    public <methods>;
}
-keep class rx.schedulers.TestScheduler {
    public <methods>;
}
-keep class rx.schedulers.Schedulers {
    public static ** test();
}

ShareSDK link

-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class **.R$* {*;}
-keep class **.R{*;}
-dontwarn cn.sharesdk.**
-dontwarn **.R$*
-dontwarn com.tencent.**
-keep class com.tencent.** {*;}

SlidingMenu link

-dontwarn com.jeremyfeinstein.slidingmenu.lib.**
-keep class com.jeremyfeinstein.slidingmenu.lib.**{*;}

Add a couple of very good code obfuscation related open source projects

AndResGuard link

Android source confusion

android-proguard-snippets link

A better project integrates almost all the common obfuscations of third-party jar packages.

Written in the end

This is the code obfuscation of the third-party open source jar packages that are currently sorted out. If you have other ways to use jar packages, leave a message for me, I will add it.

If you encounter problems in the reference process, you can ask me questions in my contact form.

Later, I will continue to introduce Android related knowledge, welcome to continue to pay attention to the update of my blog.

Reference resources

Reprinted please indicate: XueLong's blog » Android Studio code obfuscation - third-party jar obfuscation summary (continuous update)

Keywords: Android OkHttp Google ButterKnife

Added by conor.higgins on Tue, 04 Jun 2019 07:20:43 +0300