HttpClient 不会在 Android Studio 中导入 [英] HttpClient won't import in Android Studio
问题描述
我有一个用 Android Studio 编写的简单类:
I have a simple class written in Android Studio:
package com.mysite.myapp;
import org.apache.http.client.HttpClient;
public class Whatever {
public void headBangingAgainstTheWallExample () {
HttpClient client = new DefaultHttpClient();
}
}
由此我得到以下编译时错误:
and from this I get the following compile time error:
无法解析符号HttpClient
HttpClient
不是包含在 Android Studio SDK 中吗?即使不是,我也将它添加到我的 Gradle 构建中,如下所示:
Isn't HttpClient
included in the Android Studio SDK? Even if it is not, I added it to my Gradle build like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'org.apache.httpcomponents:httpclient:4.5'
}
有没有最后编译行,错误都是一样的.我错过了什么?
With or without the last compile line, the error is the same. What am I missing?
推荐答案
HttpClient
is not supported in sdk 23. 您必须使用 URLConnection
或降级到 sdk22 (编译 'com.android.support:appcompat-v7:22.2.0'
)
HttpClient
is not supported any more in sdk 23. You have to use URLConnection
or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0'
)
如果您需要 sdk 23,请将其添加到您的 gradle 中:
If you need sdk 23, add this to your gradle:
android {
useLibrary 'org.apache.http.legacy'
}
您也可以尝试将 HttpClient jar 直接下载并包含到您的项目中或使用
You also may try to download and include HttpClient jar directly into your project or use OkHttp instead
这篇关于HttpClient 不会在 Android Studio 中导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!