zoukankan      html  css  js  c++  java
  • Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题

    Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题

    针对一个post请求,android studio中无法正常导入以下两个包:

    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;

    Cannot resolve symbol NameValuePair

    最后解决方案是:

    在module文件中加入了

    android {
    ...
    useLibrary 'org.apache.http.legacy'
    
    dependencies {
        ...
        compile 'org.apache.httpcomponents:httpcore:4.4.1'
        compile 'org.apache.httpcomponents:httpclient:4.5'
    }
    
    }

    到此问题得到解决,如果还是报错出现如下:

     compile 'org.apache.httpcomponents:httpclient:4.5.5'

    出现红色报错线并提示下列错误:

    httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. less... (Ctrl+F1) 

    There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones provided in Android -- for example the apache http classes. This can lead to unexpected crashes.  To solve this, you need to either find a newer version of the library which no longer has this problem, or to repackage the library (and all of its dependencies) using something like the jarjar tool, or finally, rewriting the code to use different APIs (for example, for http code, consider using HttpUrlConnection or a library like okhttp).  Issue id: DuplicatePlatformClasses

    解决办法:

    在android中添加下列代码:

     configurations {
            all {
                exclude module: 'httpclient'
                exclude module: 'commons-logging'
            }
        }

    截图如下:

    重新点击出错语句编译即可解决。

  • 相关阅读:
    python3+requests库框架设计03-请求重新封装
    python3+requests库框架设计02-封装日志类
    [patl2-001]紧急救援
    [patl1-046]整除光棍
    latex学习
    matlab基础功能实践
    dll注入及卸载实践
    编译原理大作业暂存
    12.24逆向工程上机作业整理
    [poj1703]Find them, Catch them(种类并查集)
  • 原文地址:https://www.cnblogs.com/fwl8888/p/10391866.html
Copyright © 2011-2022 走看看