同时使用Nohttp和环信出现的问题和解决方案

前一段时间看到Yolanda的网络请求框架,项目地址是https://github.com/yanzhenjie/NoHttp,感觉是个很不错的框架,一时好奇就研究了一下,写了几个demo发现真的很好用呢,于是将我空闲时间写的项目中的网络请求框架换成了nohttp,可是当我做这些的时候才发现也是会出现一系列的问题。这里记录一下,能解决的,尽量找找解决办法。


ddssingsong大帅在唱歌

如果你项先了解一下这个项目中的知识点,人家Yolanda 已经详细的讲解了,这是他的博客地址http://blog.csdn.net/yanzhenjie1003/article/category/6097131,已经提供了很多的解决方案。

下面是项目中遇到的一些问题

1.使用Eclipse的用户只能复制粘贴喽
 项目很久以前做的,不过用的是eclipse,又想用nohttp,没办法,只好复制粘贴喽。
 不想麻烦的同学看这里 

https://github.com/ddssingsong/HttpBase

 下载完将library直接引用到项目中去,文件夹都没变
2.关于6.0权限的问题,如果引入的是nohttp.jar包,然后你用api23以下的版本,然后你还要对你的代码进行混淆,那么问题来了
> can't find referenced method 'int getColor(int,android.content.res.Resources$Theme)' in class > android.content.res.Resources
------------------------------------------------------------------------

com.yolanda.nohttp.tools.ResCompat: can't find referenced method 'android.content.res.ColorStateList getColorStateList(int,android.content.res.Resources$Theme)' in class android.content.res.Resources
------------------------------------------------------------------------

然后你将这些都-keep 和-dontwarn之后,又会出现这个

Warning: u.aly.bt: can't find referenced method 'int checkSelfPermission(java.lang.String)' in class android.content.Context

总之,代码混淆失败,为什么呢,我们来看看nohttp的源码
这里写图片描述

出错的代码:

@TargetApi(Build.VERSION_CODES.M)
    @SuppressWarnings("deprecation")
    public static int getColor(Resources resources, int resId, Theme theme) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            return resources.getColor(resId, theme);
        else
            return resources.getColor(resId);
    }

    public static ColorStateList getColorStateList(int resId) {
        return getColorStateList(resId, null);
    }

    @TargetApi(Build.VERSION_CODES.M)
    @SuppressWarnings("deprecation")
    public static ColorStateList getColorStateList(int resId, Theme theme) {
        Resources resources = NoHttp.getContext().getResources();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            return resources.getColorStateList(resId, theme);
        else
            return resources.getColorStateList(resId);

    }

对,我们将api改为23以下,就是这个错,因为只有android6.0才有checkSelfPermission这个方法呦,总之,你越往下的版本,就会出现越多的错误 ,总之混淆会出错,调到api23之后不会有这个问题

3.那么问题来了,我使用环信的即时聊天功能的时候,如果我把api跳到23之后就会出现程序闪退的现象,到论坛看看,又是6.0的问题,好吧,我又把程序api调到22,项目可以运行了,但混淆又出错了,这个让我情何以堪啊。。。。。。。

我们接下来讲述如何解决这个问题,慢慢来,不要急,我看看是解决环信还是解决nohttp

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ddssingsong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值