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
……
今天把之前的HttpClient项目移植到安卓平台上,怎么弄都报错,在网上找了很多资料依然有问题,而且都不管用,最后终于在Apache官网上找到了答案,因为Google不再支持HttpClient,并且相关库有冲突导致了以上报错,官方给出了解决方案,即调用API
提示:使用HttpClient4的项目需要设置API26以上,使用HttpClient5的项目需要最低版本API19(安卓5.0)以上
即:在Gradle中加入依赖(注意不需要手动导入jar包)
注意:点击构造,会自动下载HttpClient5的相关依赖包,不需要手动导入!
dependencies {
api 'com.github.ok2c.hc5.android:httpclient-android:0.1.0'
}
点击构造,会自动下载HttpClient5的相关依赖包,不需要手动导入!
对More than one file was found with OS independent path 'META-INF/DEPENDENCIES的解决方法是,在Gradle加入packagingOptions:
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'
}
完美解决以上在安卓下使用HttpClient的各种问题!