前一段时间看到Yolanda
的网络请求框架,项目地址是https://github.com/yanzhenjie/NoHttp,感觉是个很不错的框架,一时好奇就研究了一下,写了几个demo发现真的很好用呢,于是将我空闲时间写的项目中的网络请求框架换成了nohttp,可是当我做这些的时候才发现也是会出现一系列的问题。这里记录一下,能解决的,尽量找找解决办法。
ddssingsong大帅在唱歌
如果你项先了解一下这个项目中的知识点,人家Yolanda
已经详细的讲解了,这是他的博客地址http://blog.youkuaiyun.com/yanzhenjie1003/article/category/6097131,已经提供了很多的解决方案。
下面是项目中遇到的一些问题
1.使用Eclipse的用户只能复制粘贴喽
项目很久以前做的,不过用的是eclipse,又想用nohttp,没办法,只好复制粘贴喽。
不想麻烦的同学看这里
下载完将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