当前位置:   article > 正文

android 常见异常解决_failed resolution of:

failed resolution of:



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)

                {

 

                }

            });

 


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/915120?site=
推荐阅读
相关标签
  

闽ICP备14008679号