当我将eclipse导入android studio时如何修复错误?(作为build.gradle的编译时依赖)

时间:2016-04-02 13:40:22

标签: android build.gradle

当我将项目eclipse导入android studio时。它使编译错误。我想尝试修复关注:How to add Apache HTTP API (legacy) as compile-time dependency to build.grade for Android M?但它无效。请帮帮我!

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/annotation/GuardedBy.class

文件build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "vae.vnsupermark.com"
        minSdkVersion 14
        targetSdkVersion 23
        multiDexEnabled = true
//        versionCode 1
//        versionName "1.0"
        ndk {
            moduleName "vnsm"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'


    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
   // compile 'com.android.support:appcompat-v7:20.0.0'
//    compile 'com.google.android.gms:play-services:+'
    compile 'com.google.android.gms:play-services:4.0.30'
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/error-reporter.jar')
    //compile files('libs/httpclient-4.0.1.jar')
    compile files('libs/mail.jar')
    compile files('libs/universal-image-loader-1.9.3.jar')
}

1 个答案:

答案 0 :(得分:0)

你应该删除

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

因为它仍然会编译库(以及libs文件夹中的所有其他jar),因为它显然不会从libs文件夹中删除。 在此更改后,注释掉

//compile files('libs/httpclient-4.0.1.jar')

将真正按预期工作:)