Android 项目混淆系列2

这篇接着上篇,上篇文章已经大概介绍了一些常见的坑,以及需要混淆的地方,这篇文章是对上篇的补充,也是最近碰到的一些坑。
首先,讲一下这次遇到的坑,就是环信的。开始已经按官方的混淆,结合网上的一些文章做的混淆,代码如下:
-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.** {*;}
如果使用easeui库,需要这么写
-keep class com.hyphenate.easeui.utils.EaseSmileUtils {*;}
2.0.9后加入语音通话功能,如需使用此功能的api,加入以下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.** {*;}
环信3.0
-keep class com.hyphenate.** {*;}
-dontwarn com.hyphenate.**

但是在打包后,总是启动失败,这是很头疼的问题,可能大部分人会想到去写段代码去服务器看错误日志,这里教大家一个小技巧,其实我们不用那么麻烦,只需要用一个root的手机,把日志打开,同时在打包的时候也记得把自己项目的日志打开,在
Android 项目混淆系列2_第1张图片
输入自己的包名,然后就可以查看到报错信息了,之后我就发现是我的环信出了问题//初始化
EMClient.getInstance().init(this, options);

然后就在网上寻找答案,最后是发现还需要加一行混淆代码:

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

完整如下:

###-----------------环信-------------------#######
-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.** {*;}
#如果使用easeui库,需要这么写
-keep class com.hyphenate.easeui.utils.EaseSmileUtils {*;}
#2.0.9后加入语音通话功能,如需使用此功能的api,加入以下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.** {*;}
#环信3.0
-keep class com.hyphenate.** {*;}
-dontwarn  com.hyphenate.**
-keep class com.superrtc.** {*;}

问题解决~~
下面附上一些常见的第三方开源项目的混淆

# OkHttp3
-dontwarn okhttp3.logging.**
-keep class okhttp3.internal.**{*;}
-dontwarn okio.**
# Retrofit
# Retrofit 混淆代码
-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.** { *; }
#----------------------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混淆 ###############
# # -------------------------------------------

-dontwarn org.springframework.**
-keepattributes *Annotation*
-dontwarn org.androidannotations.**
-keep class org.androidannotations.** {*;}
###-----------------环信-------------------#######
-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.** {*;}
#如果使用easeui库,需要这么写
-keep class com.hyphenate.easeui.utils.EaseSmileUtils {*;}
#2.0.9后加入语音通话功能,如需使用此功能的api,加入以下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.** {*;}
#环信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 * ;
}
###########友盟###########
-keepclassmembers class * {
   public  (org.json.JSONObject);
}
-keep public class com.lvdao123.app.R$*{
public static final int *;
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
###########butterknife############
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* ;
}

-keepclasseswithmembernames class * {
    @butterknife.* ;
}
#######################高德地图################################
-dontwarn org.springframework.**
-keepattributes *Annotation*
-dontwarn org.androidannotations.**
-keep class org.androidannotations.** {*;}
#3D 地图 V5.0.0之前:
-keep   class com.amap.api.maps.**{*;}
-keep   class com.autonavi.amap.mapcore.*{*;}
-keep   class com.amap.api.trace.**{*;}

#3D 地图 V5.0.0之后:
-keep   class com.amap.api.maps.**{*;}
-keep   class com.autonavi.**{*;}
-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.**{*;}
#由于当前程序并没有使用到搜索服务以及其它服务,所以可以在混淆规则中忽略它#
-dontwarn com.amap.api.mapcore2d.MapMessage

#导航
-keep class com.amap.api.navi.**{*;}
-keep class com.autonavi.**{*;}
###############微信##################
-keep class com.tencent.mm.opensdk.** {
   *;
}
-keep class com.tencent.wxop.** {
   *;
}
-keep class com.tencent.mm.sdk.** {
   *;
}
-dontwarn com.tencent.mm.**
-keep class com.tencent.mm.**{*;}
###################支付宝####################
-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.sdk.app.H5PayCallback {
    ;
    ;
}
-keep class com.alipay.android.phone.mrpc.core.** { *; }
-keep class com.alipay.apmobilesecuritysdk.** { *; }
-keep class com.alipay.mobile.framework.service.annotation.** { *; }
-keep class com.alipay.mobilesecuritysdk.face.** { *; }
-keep class com.alipay.tscenter.biz.rpc.** { *; }
-keep class org.json.alipay.** { *; }
-keep class com.alipay.tscenter.** { *; }
-keep class com.ta.utdid2.** { *;}
-keep class com.ut.device.** { *;}

最后再教大家一个小技巧,当混淆时,有一些不知道混淆代码的包是,最简单的方法就是

-dontwarn org.apache**
-keep class org.apache** { *;}
-dontwarn 包名**
-keep class 包名 **  { *;}

基本都可以解决,以上就是我自己的一点项目总结,能力有限,不足之处,敬请拍砖~~,最后祝大家生活愉快!

你可能感兴趣的:(Android开发经验)