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'
}
}

截图如下:

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

Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题的更多相关文章

  1. Android Studio中导入v4,v7和recyclerview-v7包的方法

    概述 Android Studio中新建工程中会默认导入v7的包,即在gradle中默认配置了com.android.support:appcompat-v7:x.x.x的依赖.但是不会默认为我们配置 ...

  2. Android开发的小技巧,在Android Studio中使用Designtime Layout Attributes

    在编写xml文件时,为了预览效果,经常会使用默认填上一些内容,比如TextView时,随便写上一个text <TextView ... android:text="Name:" ...

  3. android studio 中移除module和恢复module

    一.移除Android Studio中module 在Android Studio中想要删除某个module时,在Android Studio中选中module,右键发现没有delete,如图: An ...

  4. Android Studio中Button等控件的Text中字符串默认大写的解决方法

    初学Android的时候,在Android Studio中xml里面添加一个Button.EditText等控件后,它的Text总是会显示大写,即使你输入的字符串是小写也不行,控制字符串大小写的属性是 ...

  5. .Net程序员之不学Java做安卓开发:Android Studio中的即时调试窗口

    对学.Net的人来说,JAVA开发是一场噩梦. .net中的即时窗口,调试时直接在里面写代码,对程序中的各种方法/属性进行调用,很方便. Android Studio中找了好久,参考如下网址,也有类似 ...

  6. 如何将Eclipse中的项目迁移到Android Studio 中

    如何将Eclipse中的项目迁移到Android Studio 中 如果你之前有用Eclipse做过安卓开发,现在想要把Eclipse中的项目导入到Android Studio的环境中,那么首先要做的 ...

  7. 在android studio 中使用applicationid的问题

    现在我需要对项目app的某个功能做性能测试,主要测试耗电量的多少. 1.我想到的方式是,我需要在同一台手机测试,同一个应用,需要安装在手机两次,第二次安装不覆盖第一次的安装. 在android stu ...

  8. Android studio 中的配置编译错误总结

    1.编译Andorid 工程的时候,有时候出现gradle 报下面的错误. Error:(1, 0) Cause: com/android/build/gradle/LibraryPlugin : U ...

  9. Android Studio中清单文件改versionCode和versionName没效果的原因

    在Android Studio中,项目的versionCode 和versionName 的控制不是在AndroidManifest.xml清单文件中更改的,而是在项目的build.gradle中更改 ...

随机推荐

  1. CentOS查看内核版本、系统版本、系统位数

    http://blog.51cto.com/ultrasql/1640435

  2. Centos 安装 Wireshark

    Wireshark是一款数据包识别软件,应用很广泛. yum install wireshark yum install wireshark-gnome

  3. 关于JBoss日志中的报错Exception in thread "AWT-EventQueue-0"的解决记录

    一.前情提要 操作系统:Windows Server 2008 R2,JDK版本:1.6.0_45,应用容器:JBoss 4.2.3 GA.所部署的应用均为Web型项目,没有任何图形相关的项目. 二. ...

  4. Codeforces Round #357 (Div. 2) A. A Good Contest 水题

    A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...

  5. UVA 10177 Sqr/Rects/Cubes/Boxes?

    Problem J (2/3/4)-D Sqr/Rects/Cubes/Boxes? Input: standard input Output: standard output Time Limit: ...

  6. 详解linux中的ps命令

    Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...

  7. POJ 1330 Nearest Common Ancestors (LCA,dfs+ST在线算法)

    Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14902   Accept ...

  8. jquery的closest方法和parents方法的区别

    今天第一次看到closest方法,以前也从来没用过. 该方法从元素本身开始往上查找,返回最近的匹配的祖先元素. 1.closest查找开始于自身,parents开始于元素父级 2.closest向上查 ...

  9. leetcode第一刷_Restore IP Addresses

    字符串的问题真是难.一般递归比較好写代码,一般地归还会超时,并且測试用例特别多.. 这道题刚拿到手时直接慌了,这情况也太多了.后来冷静下来想想,事实上还是比較单纯的. 一个ip地址,肯定是四个整数加三 ...

  10. Running multiple instances of Xamarin Studio on a Mac

    I love developing software on my MacBook Air! I got the latest version with the maximum possible spe ...