Android的摇篮的Apache的HttpClient不存在?不存在、摇篮、Android、HttpClient

2023-09-04 22:57:45 作者:侠气

我想一个的IntelliJ项目转换到Android Studio的摇篮系统,但我正在与Apache的HttpClient的错误?我失去了一些东西,是我收到的错误如下:

I am trying to convert an IntelliJ project to the Gradle system of Android Studio but I am running into errors with Apache HttpClient? Am I missing something, the errors I am getting are as follows:

Error:(10, 30) error: package org.apache.http.client does not exist
Error:(11, 30) error: package org.apache.http.client does not exist
Error:(12, 37) error: package org.apache.http.client.entity does not exist
Error:(13, 38) error: package org.apache.http.client.methods does not exist
Error:(14, 38) error: package org.apache.http.client.methods does not exist
Error:(15, 38) error: package org.apache.http.client.methods does not exist
Error:(16, 35) error: package org.apache.http.impl.client does not exist
Error:(134, 33) error: cannot find symbol class HttpUriRequest
Error:(164, 39) error: cannot find symbol class HttpUriRequest
Error:(106, 17) error: cannot find symbol class HttpGet
Error:(106, 39) error: cannot find symbol class HttpGet
Error:(117, 17) error: cannot find symbol class HttpPost
Error:(117, 40) error: cannot find symbol class HttpPost
Error:(125, 43) error: cannot find symbol class UrlEncodedFormEntity
Error:(135, 9) error: cannot find symbol class HttpClient
Error:(135, 33) error: cannot find symbol class DefaultHttpClient
Error:(155, 18) error: cannot find symbol class ClientProtocolException
Error:(165, 9) error: cannot find symbol class HttpClient
Error:(165, 33) error: cannot find symbol class DefaultHttpClient
Error:(185, 18) error: cannot find symbol class ClientProtocolException

我build.gradle文件具有以下依存关系:

My build.gradle file has the following dependencies:

dependencies {
    compile 'com.google.android.gms:play-services:+'
    compile 'org.apache.httpcomponents:httpclient:4.2.6'
    compile 'org.apache.httpcomponents:httpmime:4.2.6'
    compile files('libs/core.jar')
}

这似乎是一个很多人都得到了类似的问题,但没有SO或谷歌有一个解决办法,所以我希望这个问题将有助于未来的搜索。

It seems a lot of people are getting a similar problem but neither SO or Google have a solution so I am hoping this question will help future searchers.

推荐答案

我有这个问题,然后发现这些页面: 在这里,你可以看到,阿帕奇库pcated德$ P $,但它不会被删除,所以它应该工作。它没有。 http://developer.android.com/reference/org/apache/http/package-summary.html

I had this problem and then found these pages: Here you can see that apache library is deprecated, but it's not removed, so it should work. It doesn't. http://developer.android.com/reference/org/apache/http/package-summary.html

在这里,你可以看到如何将Apache的库项目http://developer.android.com/$p$pview/behavior-changes.html#behavior-apache-http-client

And here you can see how to include apache library to your project http://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client

我通过添加以下到我的build.gradle文件的建议,在第二个环节解决问题。

I resolved problem by adding following to my build.gradle file as recommended in second link.

android {
    useLibrary 'org.apache.http.legacy'
}

然而,如果你使用的是摇篮1.3.0-β2,所以你必须将它添加到buildscript相关性,这仅适用:

However this only works if you are using gradle 1.3.0-beta2, so you will have to add this to buildscript dependencies:

classpath 'com.android.tools.build:gradle:1.3.0-beta2'

希望这有助于。

Hope this helps.