无法在 Android Studio 中解析符号 HttpGet、HttpClient、DefaultHttpClient
Cannot resolve symbol HttpGet,HttpClient,DefaultHttpClient in Android Studio
嗨,我是 android 的新手,在我的应用程序中我正在与服务集成,所以当我导入所有这些 jar 文件时。它给出了一个错误:
Cannot resolve symbol HttpGet,HttpClient,DefaultHttpClient.
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
我的构建 gradle:-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
}
HttpClient 在 API 级别 22 中被弃用,在 API 级别 23 中被移除。你必须使用 URLConnection
.
如果您无论如何都需要 23,请将其添加到您的 gradle::
android {
useLibrary 'org.apache.http.legacy'
}
注意:相反,我建议使用 OkHttp。
Apache Http 已弃用。添加
useLibrary org.apache.http.legacy
在应用的 build.gradle 文件中的 defaultConfig 中使用 apache httpclient。
HttpClient
在 API Level 22
中弃用并在 API Level 23
中删除
因此,如果您的目标是 API Level 23
或 >=23
,那么您需要使用
useLibrary 'org.apache.http.legacy'
在 build.gradle
文件中。
这也是很好的库 http://loopj.com/android-async-http/,支持 API level 23
和 >=23
初读此文
Android 6.0 release removes support for the Apache HTTP client. If
your app is using this client and targets Android 2.3 (API level 9) or
higher, use the HttpURLConnection class instead. This API is more
efficient because it reduces network use through transparent
compression and response caching, and minimizes power consumption. To
continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1" // Set Yours
useLibrary 'org.apache.http.legacy' // You should add this
}
嗨,我是 android 的新手,在我的应用程序中我正在与服务集成,所以当我导入所有这些 jar 文件时。它给出了一个错误:
Cannot resolve symbol HttpGet,HttpClient,DefaultHttpClient.
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
我的构建 gradle:-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
}
HttpClient 在 API 级别 22 中被弃用,在 API 级别 23 中被移除。你必须使用 URLConnection
.
如果您无论如何都需要 23,请将其添加到您的 gradle::
android {
useLibrary 'org.apache.http.legacy'
}
注意:相反,我建议使用 OkHttp。
Apache Http 已弃用。添加
useLibrary org.apache.http.legacy
在应用的 build.gradle 文件中的 defaultConfig 中使用 apache httpclient。
HttpClient
在 API Level 22
中弃用并在 API Level 23
因此,如果您的目标是 API Level 23
或 >=23
,那么您需要使用
useLibrary 'org.apache.http.legacy'
在 build.gradle
文件中。
这也是很好的库 http://loopj.com/android-async-http/,支持 API level 23
和 >=23
初读此文
Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1" // Set Yours
useLibrary 'org.apache.http.legacy' // You should add this
}