Apq*_*pqu 255 android intellij-idea gradle android-studio android-gradle-plugin
我正在尝试将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
Run Code Online (Sandbox Code Playgroud)
我的build.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')
}
Run Code Online (Sandbox Code Playgroud)
似乎很多人都遇到了类似的问题,但SO或Google都没有解决方案,所以我希望这个问题能够帮助未来的搜索者.
Jin*_*inu 516
如果你在build.gradle中使用target sdk作为23添加下面的代码
android{
compileSdkVersion 23
buildToolsVersion '23.0.1'
useLibrary 'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)
并将您的buildscript更改为
classpath 'com.android.tools.build:gradle:1.3.0'
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请点击此链接
小智 92
我遇到了这个问题然后找到了这些页面:在这里你可以看到apache库已被弃用,但它没有被删除,所以它应该可以工作.它没有.
见.
在这里,您可以看到如何将apache库包含到您的项目中
见.
我通过在第二个链接中建议的build.gradle文件中添加以下内容来解决问题.
android {
useLibrary 'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)
但是,这仅在您使用gradle 1.3.0-beta2或更高版本时才有效,因此如果您使用的是较低版本,则必须将其添加到buildscript依赖项中:
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
Dar*_*iya 49
将此库添加到 build.gradle
android {
useLibrary 'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)
Ben*_*tte 38
我建议你用新的HttpURLConnection替换已弃用的apache HttpClient.
这是一个更清洁的解决方案,它很容易迁移,通常最好坚持最新的SDK更改,而不是试图破解/修补/解决方法:你通常后悔:)
步骤1
HttpGet httpGet = new HttpGet(url);
Run Code Online (Sandbox Code Playgroud)
变为:
URL urlObj = new URL(url);
Run Code Online (Sandbox Code Playgroud)
第2步
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpResponse response = httpClient.execute(httpGet, localContext);
InputStream is = response.getEntity().getContent();
Run Code Online (Sandbox Code Playgroud)
变为:
HttpURLConnection urlConnection = (HttpURLConnection) urlObj.openConnection();
InputStream is = urlConnection.getInputStream();
Run Code Online (Sandbox Code Playgroud)
第2步之二
int status = response.getStatusLine().getStatusCode();
Run Code Online (Sandbox Code Playgroud)
变为:
int status = urlConnection.getResponseCode();
Run Code Online (Sandbox Code Playgroud)
do0*_*o01 37
副本org.apache.http.legacy.jar是在Android/Sdk/platforms/android-23/optional文件夹中,以app/libs
并将此行添加到app.gradle文件中
compile files('libs/org.apache.http.legacy.jar')
Run Code Online (Sandbox Code Playgroud)
但是如果你使用更多jar库,你可以使用这种方式
compile fileTree(dir: 'libs', include: ['*.jar'])
Run Code Online (Sandbox Code Playgroud)
小智 13
基本上你需要做的就是添加:
useLibrary 'org.apache.http.legacy'
Run Code Online (Sandbox Code Playgroud)
到你的build.gradle文件.
我遇到了类似的问题,你可能能够使用类似的方法让它工作.
首先,使用当前配置尝试此操作,httpclient从httpmime以下位置排除:
dependencies {
compile 'com.google.android.gms:play-services:+'
compile ('org.apache.httpcomponents:httpmime:4.2.6'){
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient:4.2.6'
}
Run Code Online (Sandbox Code Playgroud)
就我而言,我使用以下罐子修复它:
然后,在的build.gradle,排除httpclient来自httpmime:
dependencies {
compile 'com.google.android.gms:play-services:+'
compile('org.apache.httpcomponents:httpmime:4.3.5') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
}
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题.Daniel Nugent的回答有点帮助(在听完他的建议之后HttpResponse- 但HttpClient仍然缺失了).
所以这就是为我解决的问题:
4.5.1.zip从二进制部分httpcore-4.4.3和httpclient-4.5.1.jar在project/libs文件夹中希望能帮助到你.
Jinu和Daniel的完美答案
除此之外,如果您的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'
Run Code Online (Sandbox Code Playgroud)
否则,如果您的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'
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我所做的,它对我有用.
第1步:在build.grade中添加它(模块:app)
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
Run Code Online (Sandbox Code Playgroud)
第2步:同步项目并完成.
| 归档时间: |
|
| 查看次数: |
208532 次 |
| 最近记录: |