Rolando Corratge Nieves
Rolando Corratge Nieves

Reputation: 1233

Setup Updated Apache Http Components for android

I use a code with apache HttpClient 4.5 thats works fine in a separated java aplication, when I bring to android project I have this error

java.lang.nosuchfielderror org.apache.http.conn.ssl.allowallhostnameverifier

code:

SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),new HostnameVerifier(){
            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        });  

I import the same libs , i googleit and says a duplicate reference or a jar missed but nothing I download the jar from here https://hc.apache.org/downloads.cgi If the problems is in the jars that are no compatible with android I like to find the correct jars without using gradle maven or something like this because the mayor time im offline and when online only can navigate the web Thanks

Upvotes: 0

Views: 161

Answers (1)

Derek Fung
Derek Fung

Reputation: 8211

You cannot import httpclient, because it would create conflict with existing library.

However you may want to use this, this is the official way suggested by apache

https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

Background

Google Android 1.0 was released with a pre-BETA snapshot of Apache HttpClient. To coincide with the first Android release Apache HttpClient 4.0 APIs had to be frozen prematurely, while many of interfaces and internal structures were still not fully worked out. As Apache HttpClient 4.0 was maturing the project was expecting Google to incorporate the latest code improvements into their code tree. Unfortunately it did not happen. Version of Apache HttpClient shipped with Android has effectively become a fork. Eventually Google decided to discontinue further development of their fork while refusing to upgrade to the stock version of Apache HttpClient citing compatibility concerns as a reason for such decision. As a result those Android developers who would like to continue using Apache HttpClient APIs on Android cannot take advantage of newer features, performance improvements and bug fixes.

Apache HttpClient 4.3 port for Android is intended to remedy the situation by providing official releases compatible with Google Android.

Alternatively, you can also consider okhttp, however, seems okhttp is now included on Android M, I have not tested if it would have similar conflict. okhttp, has two type of wrapper, one is similar to urlConnection, one is similar to httpclient, you should be able to migrate in a very short time.

https://github.com/square/okhttp

Upvotes: 1

Related Questions