[英]Building Android instrumented tests
我一直在关注android测试codelab并试图以类似的方式建模我的应用程序。 这样做并没有那么好。 当我尝试运行/构建我的android测试时,在使用支持库类(如AppCompatActivity和TextInputLayout)时会出错。 错误说:
The type android.support.design.widget.TextInputLayout cannot be found in source files, imported jack libs or the classpath
我运行了./gradlew app:dependencies
,实际上这些在类路径中找不到:
androidTestCompile - Classpath for compiling the androidTest sources.
+--- com.android.support.test:runner:0.5
| +--- com.android.support:support-annotations:23.1.1 -> 25.3.1
| +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| \--- com.android.support.test:exposed-instrumentation-api-publish:0.5
+--- com.android.support.test:rules:0.5
| \--- com.android.support.test:runner:0.5 (*)
+--- com.android.support.test.espresso:espresso-core:2.2.2
| +--- com.squareup:javawriter:2.1.1
| +--- com.android.support.test:rules:0.5 (*)
| +--- com.android.support.test:runner:0.5 (*)
| +--- javax.inject:javax.inject:1
| +--- org.hamcrest:hamcrest-library:1.3
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- org.hamcrest:hamcrest-integration:1.3
| | \--- org.hamcrest:hamcrest-library:1.3 (*)
| \--- com.google.code.findbugs:jsr305:2.0.1
+--- com.android.support.test.espresso:espresso-contrib:2.2.2
| +--- com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:2.0
| | \--- org.hamcrest:hamcrest-core:1.3
| \--- com.android.support.test.espresso:espresso-core:2.2.2 (*)
\--- com.android.support.test.espresso:espresso-intents:2.2.2
\--- com.android.support.test.espresso:espresso-core:2.2.2 (*)
我的build.gradle文件包含以下内容:
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:percent:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
...
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile "com.android.support.test.espresso:espresso-contrib:2.2.2"
androidTestCompile "com.android.support.test.espresso:espresso-intents:2.2.2"
}
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:25.3.1"
}
configurations.compile.dependencies.each { compileDependency ->
println "Excluding compile dependency: ${compileDependency.getName()}"
configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
}
}
请注意configurations.all
和直接从codelab获取的configurations.compile
。 我尝试将支持库添加为androidTestCompile
依赖项,但似乎什么也没做。 当我删除configurations.compile
块时,我可以在androidTestCompile
的依赖关系树中看到支持库,但是构建本身仍然失败并出现相同的错误。
不幸的是我无法发布整个代码。 有没有人碰到这样的事情? 有关如何解决此问题的任何想法?
更新:
为了澄清,在常规调试和发布版本中,一切都很有效。 只有在运行androidTest构建时才会看到此错误。
更新2:
问题似乎是杰克构建工具链。 我还不确定如何解决这个问题。
我终于找到了答案。
此问题特定于使用jack工具链和Support Repository / Google Repository v46 。 使用Google Repository版本45时,一切都很好,但版本46打破了仪表化测试的构建。 我想,一旦AS 2.4出现了对Java 1.8的官方支持,这无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.