android 常见异常解决



android studio配置:

异常:Failed resolution of:Lokhttp3/OkHttpClient;

解决方法:添加依赖项:

compile files('libs/okhttp-3.3.1.jar')
compile 'com.squareup.okhttp:okhttp:2.0.0'

 

异常:Failed resolution of:Lokio/ForwardingTimeout;

解决方法:添加依赖项:

compile files('libs/okio-1.6.0.jar')

异常:Duplicate files copied in APKMETA-INF/maven/com.squareup.okio/okio/pom.properties

还需要build.gradle添加:

packagingOptions {
    exclude 'META-INF/NOTICE.txt'
    
exclude'META-INF/LICENSE.txt'
   
exclude 'META-INF/DEPENDENCIES.txt'
   
exclude 'META-INF/NOTICE'
   
exclude 'META-INF/LICENSE'
   
exclude 'META-INF/DEPENDENCIES'
   
exclude 'META-INF/dependencies.txt'
   
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
   
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties'
   
exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
   
exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}

 

官网:

https://github.com/square/okhttp

 

github例子:

https://github.com/hongyangAndroid/okhttp-utils

 

简单封装:

https://github.com/neil2hw/OkHttpManager/blob/master/OkHttpManager.java

 

使用例子:

 OkHttpClient client = new OkHttpClient();

URL url = null;
try {
   url = new URL("http://blog.csdn.net/gaolu");
   Request request = new Request.Builder().url(url).build();

   Response response =client.newCall(request).execute();
   String aaa = response.body().string();
   Log.e("aaa", aaa);
} catch (MalformedURLException e1) {
   e1.printStackTrace();
} catch (IOException e1) {
   e1.printStackTrace();
}

使用例子:

String url="http://www.csdn.net/";

OkHttpUtils

    .get()

    .url(url)

    .addParams("username","hyman")

    .addParams("password","123")

    .build()

    .execute(newStringCallback()

            {

                @Overridepublicvoid onError(Request request, Exception e)

                {

 

                }

 

                @Overridepublicvoid onResponse(String response)

                {

 

                }

            });

 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

AI算法网奇

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

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

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

打赏作者

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

抵扣说明:

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

余额充值