Android Project Confusion Series 2

Keywords: Google Apache OkHttp Java

When the project goes online, it often encounters confusion. The previous article has outlined some common pits, as well as the areas needing confusion. This article is a supplement to the previous article, but also some pits encountered recently.
First of all, I would like to talk about the pit I encountered this time, which is the circular letter. The code is as follows:
-dontwarn com.easemob.**
-keep class com.easemob.** {*;}
-keep class org.xmlpull.** {*;}
-keep class com.squareup.picasso.* {*;}
-keep class com.hyphenate.* {*;}
-keep class com.hyphenate.chat.** {*;}
-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
If you use easeui libraries, you need to write this
-keep class com.hyphenate.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.** {*;}
-keep class com.easemob.** {*;}
ENVIRONMENT 3.0
-keep class com.hyphenate.** {*;}
-dontwarn com.hyphenate.**
But after packaging, it always fails to start, which is a headache. Maybe most people will think of writing code to read the error log on the server. Here we teach you a little trick. In fact, we don't need to be so troublesome. We just need to use a root cell phone to open the log. At the same time, when packaging, we also remember to open the log of our project.

Enter your own package name, and then you can see the error message, and then I found that my ring letter had a problem // initialization.
EMClient.getInstance().init(this, options);
Then I looked for the answer on the internet. Finally, I found that I needed to add a line of obfuscation code.

    -keep class com.superrtc.** {*;}

Complete as follows:

###-----------------Circular letter-------------------#######
-dontwarn  com.easemob.**
-keep class com.easemob.** {*;}
-keep class org.xmlpull.** {*;}
-keep class com.squareup.picasso.* {*;}
-keep class com.hyphenate.* {*;}
-keep class com.hyphenate.chat.** {*;}
-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
#If you use easeui libraries, you need to write this
-keep class com.hyphenate.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.** {*;}
-keep class com.easemob.** {*;}
#ENVIRONMENT 3.0
-keep class com.hyphenate.** {*;}
-dontwarn  com.hyphenate.**
-keep class com.superrtc.** {*;}

Problem solving~~
Attached below are some common obfuscations of third-party open source projects

# OkHttp3
-dontwarn okhttp3.logging.**
-keep class okhttp3.internal.**{*;}
-dontwarn okio.**
# Retrofit
# Retrofit obfuscation code
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
# 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;
}
##############okhttp##########
-dontwarn com.squareup.okhttp.
-keep class com.squareup.okhttp.** {*;}
-keep class com.zhy.http.okhttp.** {*;}
-keep interface com.squareup.okhttp.** {*;}
-dontwarn okio.*
-keep class com.google.gson.** {*;}
-keep class com.google.gson.JsonObject { *; }
################gson##################
-dontwarn com.google.code.gson.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.google.gson.Gson.** {*;}
-keep class com.google.**{*;}
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class com.google.gson.examples.android.model.** { *; }
-keep class org.json.** { *; }
#----------------------------------------------------#
-keep class com.lvdao.network.entity.request.** { *; }
-keep class com.lvdao.network.entity.response.** { *; }
#----------------------------------------------------#
-keep class com.lvdao123.app.entity.** { *; }
-keep class com.lvdao123.app.entity.db.entity.** { *; }
-keep class com.lvdao123.app.citypicker.model.** { *; }
#----------------------baidu---------------------#

-keep class com.baidu.** {*;}
-keep class vi.com.** {*;}
-keep class vi.com.gdi.bgl.**{*;}
-dontwarn com.baidu.**
-keep class com.baidu.mapapi.** {*;}
#glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
# # -------------------------------------------
# # ############### androidannotations confusion ###############
# # -------------------------------------------

-dontwarn org.springframework.**
-keepattributes *Annotation*
-dontwarn org.androidannotations.**
-keep class org.androidannotations.** {*;}
###-----------------Circular letter-------------------#######
-dontwarn  com.easemob.**
-keep class com.easemob.** {*;}
-keep class org.xmlpull.** {*;}
-keep class com.squareup.picasso.* {*;}
-keep class com.hyphenate.* {*;}
-keep class com.hyphenate.chat.** {*;}
-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
#If you use easeui libraries, you need to write this
-keep class com.hyphenate.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.** {*;}
-keep class com.easemob.** {*;}
#ENVIRONMENT 3.0
-keep class com.hyphenate.** {*;}
-dontwarn  com.hyphenate.**
-keep class com.superrtc.** {*;}
#-------------  -----------------
#####glide######
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
#####litepal######
-dontwarn org.litepal.**
-keep class org.litepal.** { *; }
-keep enum org.litepal.**
-keep interface org.litepal.** { *; }
-keep public class * extends org.litepal.**
-keepattributes Annotation
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * extends org.litepal.crud.DataSupport{
private * ;
}

Finally, I'll teach you a little trick. When confusing, there are some packages that don't know about confusing code. The easiest way is to do that.

-dontwarn org.apache**
-keep class org.apache** { *;}
- dontwarn package name**
- keep class package name ** {*;}

Basically can be solved, the above is my own project summary, limited capacity, shortcomings, please pat a brick, and finally wish you a happy life!

Posted by sixdollarshirt on Thu, 27 Jun 2019 17:23:10 -0700