【问题标题】:Error:Execution failed for task in android studio错误:android studio中的任务执行失败
【发布时间】:2016-03-10 09:49:55
【问题描述】:

当我尝试将 jar 文件添加到我的项目时,我收到类似 Error:Execution failed for task 的错误

':app:transformClassesWithJarMergingForDebug'。 > com.android.build.api.transform.TransformException: java.util.zip.ZipException:重复条目: android studio 中的 org/apache/http/annotation/Immutable.class

build.gradle

ultConfig {
        applicationId "com.syzygy.extreme.uploadexample"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile files('libs/apache-httpcomponents-httpclient.jar')
    compile files('libs/httpcore-4.3.3.jar')
    compile files('libs/httpmime-4.0.jar')
}

【问题讨论】:

  • 发布您的build.gradle
  • duplicate entry 同一个库再调用一次
  • 依赖项 { 编译 fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1 .1' 编译 'com.android.support:design:23.1.1' 编译文件('libs/apache-httpcomponents-httpclient.jar') 编译文件('libs/httpcore-4.3.3.jar') 编译文件( 'libs/httpmime-4.0.jar') }
  • 评论此行compile files('libs/apache-httpcomponents-httpclient.jar')
  • 然后Clean-Rebuild-Run。让我通知一下。

标签: android build.gradle


【解决方案1】:

试试这个 http 核心和 mime。 100% 正常工作

android {

    repositories {
        mavenCentral()
    }
    android {
        useLibrary 'org.apache.http.legacy'
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.abcd"
        minSdkVersion 7
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {


    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5.1'
    compile('org.apache.httpcomponents:httpmime:4.3') {
        exclude module: "httpclient"
    }

    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'

    testCompile 'junit:junit:4.12'


}

【讨论】:

  • 嗨@NikPatel,您的回复对我很有用,您能否提一下如何更改版本“4.3.5.1”我正在尝试使用更新库,因为我正在尝试更新客户端库版本,例如“ 4.5.1' 但不会例外。谢谢
猜你喜欢
  • 1970-01-01
  • 2016-02-09
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-25
相关资源
最近更新 更多