Android gradle build:在APK LICENSE.txt打包期间重复文件

前端之家收集整理的这篇文章主要介绍了Android gradle build:在APK LICENSE.txt打包期间重复文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用以下gradle构建文件构建 Android测试
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }

apply plugin: 'android-library'

repositories {
  mavenCentral()
}

dependencies {
    instrumentTestCompile "junit:junit:4.+"        
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    instrumentTest.setRoot('tests')
    instrumentTest {
      java.srcDirs = ['tests/src']
      res.srcDirs = ['tests/res']
      assets.srcDirs = ['tests/assets']
      resources.srcDirs = ['tests/src']
        }        
    }
}

运行时我收到以下错误

Error: duplicate files during packaging of APK … Path in archive: LICENSE.txt
Origin 1: ….gradle/caches/artifacts-24/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar
Origin 2: ….gradle/caches/artifacts-24/filestore/org.hamcrest/hamcrest-core/1.3/jar/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar
:packageTest Failed

FAILURE: Build Failed with an exception.

  • What went wrong:
    Execution Failed for task ‘:packageTest’.
    Duplicate files at the same path inside the APK: LICENSE.txt

解决方法

Junit v4.5已将所有必需的依赖项打包到JUnit jar中.因此不需要hamcrest.jar,也没有生成双LICENSE.txt文件.

只需将依赖项更改为:

instrumentTestCompile “junit:junit:4.5+”

基本问题仍然存在 – android在其构建树中不接受两个相同的文件名.不过,这是一个很好的解决方法.

原文链接:https://www.f2er.com/android/316698.html

猜你在找的Android相关文章