【发布时间】:2015-04-10 08:56:49
【问题描述】:
我已经阅读过,有许多广泛的答案(例如 this one),但 Android 世界发展得如此之快,以至于它们似乎有点过时了,official documentation 仍然指的是带有 ADT 的 Eclipse。
我正在运行 AS 1.1,并且我正在尝试设置简单的 junit 测试以在没有 Robolectric 的情况下在模拟器上运行。如果我的build.gradle 中不包含junit,它将找不到@After、@Before 和@Test,我得到package org.junit does not exist。添加时
// unit tests
androidTestCompile 'junit:junit:4.11'
错误变成了
Error:duplicate files during packaging of APK
[...]/app/build/outputs/apk/app-debug-test-unaligned.apk
Path in archive: LICENSE.txt
Origin 1: [...]/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar
Origin 2: [...]/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'LICENSE.txt'
}
}
按照排除 LICENSE.txt 的控制台建议,它可以正常工作,但感觉就像是 hack。所以我想知道,我可能错过了什么吗?谢谢。
【问题讨论】:
-
这就是我们在项目中一直这样做的方式,这似乎是预期的方式。
-
排除 LICENSE.txt 是一种正常的做法 :) (还有 META-INF/LICENSE.txt 和 META-INF/NOTICE.txt)
-
遇到同样的问题,您的测试在哪里?
标签: android unit-testing junit android-studio