我想包括资源,仅用于测试进行编译。
I'd like to include resources to be compiled only for testing.
我在我的应用程序模块build.gradle文件如下:
I have the following in my app module build.gradle file:
android {
...
sourceSets {
androidTest {
java.srcDirs = ['src/androidTest/java']
res.srcDirs = ['src/androidTest/res']
}
}
}
在Java srcDirs路径是正确的,但如果我试图让从androidTest res目录资源,该资源无法找到。
The java srcDirs path is correct, yet if I try to get a resource from the res directory in androidTest, the resource can't be found.
我怎么能在那些只包括了测试androidTest目录资源?
How can I have resources in the androidTest directory that are only included for tests?
原来你并不需要更改默认build.gradle文件什么。
Turns out you don't need to change anything from the default build.gradle file.
的诀窍是自动生成的 R.java
文件是针对不同的资源在 androidTest
。
The trick is that the auto-generated R.java
file is different for resources in androidTest
.
如果导入语句研究
放在你的主要来源组是这样的:
If the import statement for R
somewhere in your main source set looks like:
import com.mycompany.myappname.R;
在测试文件中的import语句研究
应该是这样的:
import com.mycompany.myappname.test.R;
上一篇:安卓4.4.2仅在完整的Java code动画创建一个黑色面罩外的视图对象的边界,面罩、视图、边界、创建一个
下一篇:什么是pcated替代非德$ P $到的XmlDataDocument和的XslTransform?pcated、XmlDataDocument、XslTransform