我正在使用Android-Studio 2.2.2并且我第一次尝试使用espresso进行测试。使用附加的build.gradle,我收到了以下错误消息:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK junit/runner/smalllogo.gif
File1: /home/christian/AndroidStudioProjects/PinMoney/app/libs/junit-4.12.jar
File2: /home/christian/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar
这是app gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
def AAVersion = '4.1.0'
android {
compileSdkVersion 25
buildToolsVersion "25"
defaultConfig {
applicationId "de.cokuss.chhe.pinmoney"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENCE.txt'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile files('libs/junit-4.12.jar')
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support'
}
}
我发现了几个"复制的重复文件"搜索时遇到问题,但总是使用不同的文件只需添加
packagingOptions {
exclude 'LICENCE.txt'
exclude 'smalllogo.gif' //added
}
无济于事。
答案 0 :(得分:1)
此:
packagingOptions {
exclude 'LICENCE.txt'
exclude 'smalllogo.gif' //added
}
不是正确的解决方案,但在互联网的一点帮助下我发现我必须让它更准确。另外我发现smalllogo.gif并不是我唯一要排除的东西。这是我必须改变的重要部分:
packagingOptions {
exclude 'LICENCE.txt' // from old code
exclude 'junit/runner/smalllogo.gif'
exclude 'junit/runner/logo.gif'
exclude 'LICENSE-junit.txt'
}
我不认为这是解决此问题的最佳方法,但它确实有效。