Android Studio 0.5.1
我使用Generate gradle build files导出了我的eclipse项目LocationLab
和LocationLabTest
。
然后我将这些导入Android Studio。我已经为LocationLabTest设置了模块依赖性,因为这取决于Project Stucture中的LocationLab。
我需要测试的类似乎不在测试包的范围内。
问题是LocationLabTest找不到LocationLab包的导入包course.labs.locationlab
在LocationLabTest清单文件中,TargetPackage android:targetPackage="course.labs.locationlab"
为红色。
非常感谢任何建议,
以下是我的结构截图:
build.grade(LocationLabTest)
apply plugin: 'android'
dependencies {
compile project(':LocationLab')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion '19.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
}
}
build.grade(LocationLab)
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion '19.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
答案 0 :(得分:1)
在Gradle下,测试不在与测试代码分开的模块中;测试位于同一模块中,源位于不同的目录中。 Gradle会自动生成测试APK的 AndroidManifest.xml 文件,因此这不是您指定的内容。
在主模块的 build.gradle 文件中,您已经设置了测试文件夹:
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
因此您应该将测试代码移动到该文件夹中。您可以在http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing
找到有关在Gradle中设置测试的文档