0

Just trying to make some POST requests in an Android app. I was testing with HttpClient 4.5.3 (https://hc.apache.org/downloads.cgi) in a standalone script. Everything worked, but when I tried to add it to the Android app, I found out I need to add some repackaged dependency due to versioning issues. So I added

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'

in Gradle and synced it without issues. However, I can't import any of the classes I need to do what I need. These are the imports I need:

import org.apache.http.HttpEntity; // "HttpEntity" is highlighted red
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

What am I missing?

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
laketuna
  • 3,832
  • 14
  • 59
  • 104
  • Possible duplicate of [How do I properly import HttpClient from org.apache on Android using gradle build file?](https://stackoverflow.com/questions/15775747/how-do-i-properly-import-httpclient-from-org-apache-on-android-using-gradle-buil) – Dima Kozhevin Sep 26 '17 at 22:09
  • https://stackoverflow.com/a/34153044/3166697 check `useLibrary 'org.apache.http.legacy'` – Dima Kozhevin Sep 26 '17 at 22:09

1 Answers1

0

This works for me.

android {
    ... 
    useLibrary  'org.apache.http.legacy'
}
dependencies {
    ...
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
}
paradocslover
  • 2,932
  • 3
  • 18
  • 44
Mete
  • 2,805
  • 1
  • 28
  • 38