Cannot resolve symbol HttpGet,HttpClient,DefaultHttpClient in Android Studio
嗨,我是我的应用程序中的android新手,正在与服务集成,因此当我导入所有这些jar文件时。它给出了一个错误:
Cannot resolve symbol HttpGet,HttpClient,DefaultHttpClient.
1 2 3 4 5 | 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:-
1 2 3 4 5 6 7 8 9 | 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中已删除。您必须使用
如果您仍然需要23,请将其添加到gradle ::
1 2 3 | android { useLibrary 'org.apache.http.legacy' } |
注意:相反,我建议使用OkHttp。
中已删除
因此,如果目标
1 | useLibrary 'org.apache.http.legacy' |
。
这也是不错的库http://loopj.com/android-async-http/,它支持
不建议使用Apache Http。添加
在defaultConfig中应用程序的build.gradle文件中,以使用apache httpclient。
首先阅读此内容,无法在Android Studio中解析符号HttpGet,HttpClient,HttpResponce。
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:
1 2 3 4 5 | android { compileSdkVersion 23 buildToolsVersion"23.0.1" // Set Yours useLibrary 'org.apache.http.legacy' // You should add this } |