Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle build: duplicate files during packaging of APK LICENSE.txt

I am trying to build an Android test using the following gradle build file

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']
        }        
    }
}

When run I get the following error:

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
like image 888
Guy Avatar asked Jul 29 '13 12:07

Guy


2 Answers

Junit v4.5 has packaged all necessary dependencies into the JUnit jar. Hence no need for hamcrest.jar, and no resulting double LICENSE.txt file.

just change dependencies to:

instrumentTestCompile "junit:junit:4.5+"

The basic issue still remains - android not accepting two files names the same in its build tree. This is a good workaround, though.

like image 110
Guy Avatar answered Nov 05 '22 00:11

Guy


I noticed this commit comment in AOSP, the solution will be to exclude some files using DSL. Probably when 0.7.1 is released.

commit e7669b24c1f23ba457fdee614ef7161b33feee69
Author: Xavier Ducrohet <--->
Date:   Thu Dec 19 10:21:04 2013 -0800

    Add DSL to exclude some files from packaging.

    This only applies to files coming from jar dependencies.
    The DSL is:

    android {
      packagingOptions {
        exclude 'META-INF/LICENSE.txt'
      }
    }
like image 27
Maxime Avatar answered Nov 05 '22 01:11

Maxime