如何使用Android上棉花糖遗留的Apache HTTP客户端? [英] How to use the legacy Apache HTTP client on Android Marshmallow?
问题描述
在Android的棉花糖,谷歌已经完全删除的Apache HTTP客户端(支持链接的 此处 ),因为相比于替代它并没有出色的表现。
On Android Marshmallow, Google has completely removed the support of Apache HTTP client (link here) because it doesn't have good performance compared to the alternatives.
这也可能是造成如此多的应用程序崩溃在Android棉花糖。
This might also be the cause for so many apps crashing on Android Marshmallow.
谷歌允许你仍然可以使用这个API,只是没有内置于一体,加入这一行的摇篮文件:
Google allows you to still use this API, just not as a built in one, by adding this line to the gradle file:
useLibrary 'org.apache.http.legacy'
所以,这就是我所做的:
So, this is what I did:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
和
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.user.androidmtest"
minSdkVersion 'MNC'
targetSdkVersion 'MNC'
versionCode 1
versionName "1.0"
}
当我试了一下,它编译罚款(被显示不会出错,而且我可以运行概念验证的应用程序,因为它没有任何特殊的code),但是当我试图用一些我知道这是旧的API的一部分(如HttpClient的类)的班,我看到,它不允许我这样做。
When I tried it, it compiled fine (no errors being shown, and I could run the proof-of-concept app, as it doesn't have any special code), but when I tried using some of the classes that I know that are part of the old API (like "HttpClient" class), I see that it doesn't allow me to do so.
我知道这是不推荐使用此解决方案,但我们必须有应用程序准备好至少暂时在那里工作,直到我们上了这一切应该改变为Android棉花糖的东西的工作100%,而我们不希望惊喜崩溃的形式。
I know it's not recommended to use this solution, but we must have the app ready to work there at least temporarily, till we work 100% on all of the things that should change for Android Marshmallow, and we don't want surprises in the form of crashes.
下面是截图:
为什么会出现这种问题?我有没有正确地使用它?
Why does it occur? Did I use it correctly?
编辑:报告关于这个问题在这里:
reported about this issue here:
HTTPS://$c$c.google。 COM / P /安卓/问题/详细信息?ID = 181474
推荐答案
Android的工作室抱怨说 org.apache.http
类,如
Android Studio was complaining that org.apache.http
classes like
org.apache.http.NameValuePair
org.apache.http.client.utils.URLEncodedUtils
人失踪。
所以我添加 org.apache.http.legacy.jar
这是在
安卓/ SDK /平台/ Android的-23 /可选
文件夹为应用程序/库
So I added org.apache.http.legacy.jar
which is in
Android/Sdk/platforms/android-23/optional
folder to to app/libs
我还添加了此行我的 app.gradle
文件
I also added this line to my app.gradle
file
compile files('libs/org.apache.http.legacy.jar')
但是,如果你正在使用更多的图书馆,你可以用这样的方式
But if you're using more libraries, you can use this way
compile fileTree(dir: 'libs', include: ['*.jar'])
这解决了我所有的错误被造成的,因为谷歌移除支持的Apache HTTP客户端。
This resolved all my errors that were caused because google removed support of Apache HTTP client.
这篇关于如何使用Android上棉花糖遗留的Apache HTTP客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!