Reputation: 111
In android studio in mainactivity at the top I have the lines
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.util.EncodingUtils;
Cannot resolve symbol of HttpClient HttpPost and EncodingUtils All this marked in red.
If I remember right my project when created it was targeting api 15. My device to run it later on is lg g3.
Also I installed android studio yesterday and inside the android studio I didn't checked and installed the AVD manager packages not sure if I should or they are already installed.
This is what I see when going to AVD I see there also something Failed to load on the right top corner.
Upvotes: 2
Views: 2567
Reputation: 29436
Apache HttpClient has been deprecated and removed from Android 6 onwards as per this announcement. You should not be using it.
The recommended way now is to use HttpUrlConnection.
OR, switch to OkHttp.
Both of these are said to be much efficient than the legacy HttpClient.
Upvotes: 1
Reputation: 6287
As android removed apache libraries , you need to add those libraries yourself
to add follow these steps
1 ) download Apache HttpClient and HttpCore jar files (you can get here link)
2) copy the jar files and paste it in libs folder of your application. 3) right click on your app folder and open module setting.select dependencies tab
4)click green + button and selectFile dependency and then select your jar file. and click on dropdown and select that as "Compile"
5)if you get any error while building gradle.(Duplicate files Exception)
add this lines to build
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
}
Upvotes: 0
Reputation: 11245
You need to add this inside Build.Gradle
android
.
android {
compileSdkVersion 23
buildToolsVersion '22.0.1'
useLibrary 'org.apache.http.legacy'
}
Also add this to Dependencies
.
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
Upvotes: 3