我试图将IntelliJ项目转换为Android Studio的Gradle系统,但我遇到了Apache HttpClient错误?我是否遗漏了一些东西,我得到的错误如下:

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

我的建立。Gradle文件有以下依赖项:

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和谷歌都没有解决方案,所以我希望这个问题能帮助未来的搜索者。


当前回答

以我为例,我更新了我的android项目中的一个库。

我使用水库作为我的缓存存储解决方案:https://github.com/anupcowkur/Reservoir

我从:

compile 'com.anupcowkur:reservoir:2.1'

To:

compile 'com.anupcowkur:reservoir:3.1.0'

库作者一定是从repo中删除了commons-io库,所以我的应用程序不再工作。

我必须手动将commons-io添加到gradle:

compile 'commons-io:commons-io:2.5'

https://mvnrepository.com/artifact/commons-io/commons-io/2.5

其他回答

这就是我所做的,而且对我很有效。

步骤1:将此添加到构建中。年级(模块:应用)

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

步骤2:同步项目并完成。

将Android/Sdk/platforms/ Android -23/optional文件夹下的org.apache.http.legacy.jar复制到app/libs

并将这一行添加到app.gradle文件中

compile files('libs/org.apache.http.legacy.jar')

但是如果您正在使用更多的jar库,您可以使用这种方式

compile fileTree(dir: 'libs', include: ['*.jar'])

以我为例,我更新了我的android项目中的一个库。

我使用水库作为我的缓存存储解决方案:https://github.com/anupcowkur/Reservoir

我从:

compile 'com.anupcowkur:reservoir:2.1'

To:

compile 'com.anupcowkur:reservoir:3.1.0'

库作者一定是从repo中删除了commons-io库,所以我的应用程序不再工作。

我必须手动将commons-io添加到gradle:

compile 'commons-io:commons-io:2.5'

https://mvnrepository.com/artifact/commons-io/commons-io/2.5

吉努和丹尼尔的完美回答

除此之外 我通过使用这个解决了问题,如果你的compileSdkVersion是19(在我的情况下)

compile ('org.apache.httpcomponents:httpmime:4.3'){
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile ('org.apache.httpcomponents:httpcore:4.4.1'){
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile 'commons-io:commons-io:1.3.2'

如果你的compileSdkVersion是23 然后使用

android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    }
}

基本上你所需要做的就是添加:

useLibrary  'org.apache.http.legacy'

适合你的身材。gradle文件。