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'
}
}
截图如下:

重新点击出错语句编译即可解决。
Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题的更多相关文章
- Android Studio中导入v4,v7和recyclerview-v7包的方法
概述 Android Studio中新建工程中会默认导入v7的包,即在gradle中默认配置了com.android.support:appcompat-v7:x.x.x的依赖.但是不会默认为我们配置 ...
- Android开发的小技巧,在Android Studio中使用Designtime Layout Attributes
在编写xml文件时,为了预览效果,经常会使用默认填上一些内容,比如TextView时,随便写上一个text <TextView ... android:text="Name:" ...
- android studio 中移除module和恢复module
一.移除Android Studio中module 在Android Studio中想要删除某个module时,在Android Studio中选中module,右键发现没有delete,如图: An ...
- Android Studio中Button等控件的Text中字符串默认大写的解决方法
初学Android的时候,在Android Studio中xml里面添加一个Button.EditText等控件后,它的Text总是会显示大写,即使你输入的字符串是小写也不行,控制字符串大小写的属性是 ...
- .Net程序员之不学Java做安卓开发:Android Studio中的即时调试窗口
对学.Net的人来说,JAVA开发是一场噩梦. .net中的即时窗口,调试时直接在里面写代码,对程序中的各种方法/属性进行调用,很方便. Android Studio中找了好久,参考如下网址,也有类似 ...
- 如何将Eclipse中的项目迁移到Android Studio 中
如何将Eclipse中的项目迁移到Android Studio 中 如果你之前有用Eclipse做过安卓开发,现在想要把Eclipse中的项目导入到Android Studio的环境中,那么首先要做的 ...
- 在android studio 中使用applicationid的问题
现在我需要对项目app的某个功能做性能测试,主要测试耗电量的多少. 1.我想到的方式是,我需要在同一台手机测试,同一个应用,需要安装在手机两次,第二次安装不覆盖第一次的安装. 在android stu ...
- Android studio 中的配置编译错误总结
1.编译Andorid 工程的时候,有时候出现gradle 报下面的错误. Error:(1, 0) Cause: com/android/build/gradle/LibraryPlugin : U ...
- Android Studio中清单文件改versionCode和versionName没效果的原因
在Android Studio中,项目的versionCode 和versionName 的控制不是在AndroidManifest.xml清单文件中更改的,而是在项目的build.gradle中更改 ...
随机推荐
- perf工具crash的问题
perf抓取时系统crash的情况.找前同事了解到perf工具导致系统crash的一种情况, perf工具默认是使用cycles,这个硬件事件是使用NMI,可能会导致内核错误. 之前文档上的perf命 ...
- 一台电脑如何安装多个版本的JDK
1 . 准备两个版本的jdk我的两个jdk路径为: C:\Program Files\Java\jdk1.6.0_43 C:\Program Files\Java\jdk1.8.0_25 2 . ...
- 使用multiprocessing中的常见问题
在python的解释器中,CPython是应用范围最广的一种,其具有丰富的扩展包,方便了开发者的使用.当然CPython也不是完美的,由于全局解释锁(GIL)的存在,python的多线程可以近似看作单 ...
- [ 转载 ] Java中常用的设计模式
Java中常用的设计模式 1.单例模式 单例模式有以下特点: 1.单例类只能有一个实例. 2.单例类必须自己创建自己的唯一实例. 3.单例类必须给所有其他对象提供这一实例. 单例模式确保某个类只有一个 ...
- redis keys 命令
## 删除存在的key del key ## 序列体弱给定key,并返回被序列化的值 dump key ## 检查key是否存在 exists key ## 为给定key设置过期时间 expire k ...
- wpf企业应用之SelectButton(用于列表页之类的选择)
在企业级应用中,通常我们会遇到这样的需求,需要点击一个按钮选择列表中的一项或者多项,然后将结果显示到按钮中.这里我给自己的控件命名为SelectButton,具体效果见 wpf企业级开发中的几种常见业 ...
- Codeforces.809E.Surprise me!(莫比乌斯反演 虚树)
题目链接 \(Description\) 给定一棵树,求\[\frac{1}{n(n-1)/2}\times\sum_{i\in[1,n],j\in[1,n],i\neq j}\varphi(a_i\ ...
- java 中常用的类
java 中常用的类 Math Math 类,包含用于执行基本数学运算的方法 常用API 取整 l static double abs(double a) 获取double 的绝对值 l sta ...
- wx小程序碎碎念
对button组件的例子中,js代码的一点理解 for (var i = 0; i < types.length; ++i) { (function(type) { // 循环构建目标函数 pa ...
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力
D. Vanya and Treasure 题目连接: http://www.codeforces.com/contest/677/problem/D Description Vanya is in ...