在尝试运行测试用例时显示的APK META-INF / LICENSE错误中复制的重复文件

时间:2017-01-13 11:03:49

标签: java android appium

错误日志如下:

  

错误:任务执行失败   ':应用程序:transformResourcesWithMergeJavaResForDebug&#39 ;.   com.android.build.api.transform.TransformException:   com.android.builder.packaging.DuplicateFileException:重复文件   复制在APK META-INF / LICENSE File1中:   C:\ Users \用户MYPC.gradle \缓存\模块-2 \文件-2.1 \ org.apache.httpcomponents \ httpmime \ 4.5 \ 7bdb321e86724b16af6134a0fd22fec649eda971 \ httpmime-4.5.jar     文件2:   C:\ Users \用户MYPC.gradle \缓存\模块-2 \文件-2.1 \的xerces \ xercesImpl \ 2.11.0 \ 9bb329db1cfc4e22462c9d6b43a8432f5850e92c \ xercesImpl-2.11.0.jar     文件3:   C:\ Users \用户MYPC.gradle \缓存\模块-2 \文件-2.1 \ com.fasterxml.jackson.core \杰克逊 - 注解\ 2.6.0 \ a0990e2e812ac6639b6ce955c91b13228500476e \杰克逊 - 注解-2.6.0.jar

我在下面使用的依赖关系:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    useLibrary  'org.apache.http.legacy'

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

    testOptions {
        unitTests.returnDefaultValues = true
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'

    }

}



     dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.0'
        compile 'junit:junit:4.12'
        compile 'io.appium:java-client:3.3.0'
        compile 'com.googlecode.json-simple:json-simple:1.1.1'
        compile 'commons-lang:commons-lang:2.6'
        compile 'com.google.code.gson:gson:2.5'
        compile 'com.testdroid:testdroid-api:2.9'
        testCompile 'org.mockito:mockito-core:1.10.19'

        compile 'com.google.dagger:dagger:2.4'
        annotationProcessor 'com.google.dagger:dagger-compiler:2.4'

        configurations {
            all*.exclude group: 'commons-logging', module: 'commons-logging'
        }

    }

如何删除此错误?

1 个答案:

答案 0 :(得分:1)

您应该在 build.gradle 部分

中添加此内容
  

META-INF目录由Java 2识别和解释   用于配置应用程序,扩展的平台;

 packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'

}

然后 Clean-Rebuild-Run