Use HttpClient on Android 9.0 and above

No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/

……

More than one file was found with OS independent path 'META-INF/DEPENDENCIES

……

Today, I ported the previous HttpClient project to the Android platform, and I got an error. I found a lot of information on the Internet. There are still problems, and they are all useless. Finally, I finally found the answer on the Apache official website. Because Google no longer supports HttpClient, and The conflicts in the related libraries caused the above error, and the official gave a solution, that is, call the API

Tip: Projects using HttpClient4 need to set up API26 or above, and projects using HttpClient5 need to have minimum version API19 (Android 5.0) or above

That is: add dependencies in Gradle (note that there is no need to manually import jar packages)

Note: Clicking on the structure will automatically download the relevant dependency packages of HttpClient5 without manual import!

dependencies {
    api 'com.github.ok2c.hc5.android:httpclient-android:0.1.0'
}

Click on the structure, it will automatically download the HttpClient5 related dependencies, no need to manually import!

The solution to More than one file was found with OS independent path 'META-INF / DEPENDENCIES is to add packagingOptions in Gradle:

packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/rxjava.properties'
    }

Perfectly solve the above problems of using HttpClient under Android!

File information link: Android extension for Apache HttpClient 5.0.x

Published 6 original articles · won 7 · views 253

Guess you like

Origin blog.csdn.net/XiaoYunKuaiFei/article/details/105543103