解决新版AndroidStudio 导入HttpClient冲突
HttpClient虽然已经被Google抛弃,但是有限项目依然依赖这些库,还得用。我把Httpclient的所有库导入项目后,会产生如下错误。
Error:duplicate files during packaging of APK F:\Downloads\MyApplication7\app\build\outputs\apk\app-debug-unaligned.apk
Path in archive: META-INF/DEPENDENCIES
Origin 1: F:\Downloads\MyApplication7\app\libs\httpclient-4.5.2.jar
Origin 2: F:\Downloads\MyApplication7\app\libs\httpcore-4.4.4.jar
经过查找可以在文件中(app\build.gradle)加入以下代码消除这个问题。
- packagingOptions {
 - exclude 'META-INF/DEPENDENCIES'
 - exclude 'META-INF/NOTICE'
 - exclude 'META-INF/LICENSE'
 - exclude 'META-INF/LICENSE.txt'
 - exclude 'META-INF/NOTICE.txt'
 - exclude 'META-INF/ASL2.0'
 - exclude 'META-INF/notice.txt'
 - }
 
整个文件如下:
apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "com.xba.imagetest"
        minSdkVersion 16
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/notice.txt'
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile files('libs/httpclient-4.5.2.jar')
    compile files('libs/httpcore-4.4.4.jar')
} 相关推荐
  84457417    2014-07-09  
   84487600    2020-08-16  
   似水流年梦    2020-08-09  
   knightwatch    2020-07-26  
   fengchao000    2020-06-16  
   标题无所谓    2020-06-14  
   sicceer    2020-06-12  
   yanghui0    2020-06-09  
   yanghui0    2020-06-09  
 创建一个 HttpClient 实例,这个实例需要调用 Dispose 方法释放资源,这里使用了 using 语句。接着调用 GetAsync,给它传递要调用的方法的地址,向服务器发送 Get 请求。
  wanghongsha    2020-06-04  
   jiaguoquan00    2020-05-26  
   zhaolisha    2020-05-16  
   wanghongsha    2020-05-05  
   wanghongsha    2020-04-14  
   knightwatch    2020-04-11  
   hygbuaa    2020-03-27