[英]Building Android instrumented tests
I've been following the android testing codelab and trying to model my app in a similar manner. 我一直在关注android测试codelab并试图以类似的方式建模我的应用程序。 Doing so hasn't panned out all that well.
这样做并没有那么好。 When I try to run/build my android tests I get errors when using support library classes such as AppCompatActivity and TextInputLayout.
当我尝试运行/构建我的android测试时,在使用支持库类(如AppCompatActivity和TextInputLayout)时会出错。 The error says:
错误说:
The type android.support.design.widget.TextInputLayout cannot be found in source files, imported jack libs or the classpath
I ran ./gradlew app:dependencies
and indeed these are not found in 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 (*)
My build.gradle files has the following: 我的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()}"
}
}
Note the configurations.all
and the configurations.compile
taken directly from the codelab. 请注意
configurations.all
和直接从codelab获取的configurations.compile
。 I tried adding the support libraries as androidTestCompile
dependencies, but it seems to do nothing. 我尝试将支持库添加为
androidTestCompile
依赖项,但似乎什么也没做。 When I remove the configurations.compile
block I can see the support library in the dependency tree for androidTestCompile
but the build itself still fails with the same error. 当我删除
configurations.compile
块时,我可以在androidTestCompile
的依赖关系树中看到支持库,但是构建本身仍然失败并出现相同的错误。
Unfortunately I can't release the entire code. 不幸的是我无法发布整个代码。 Has anyone run into something like this?
有没有人碰到这样的事情? Any thoughts on how to resolve this?
有关如何解决此问题的任何想法?
UPDATE: 更新:
To clarify, everything works great during regular debug and release builds. 为了澄清,在常规调试和发布版本中,一切都很有效。 Only when running the androidTest builds do I see this error.
只有在运行androidTest构建时才会看到此错误。
UPDATE 2: 更新2:
The issue appears to be around the jack build toolchain. 问题似乎是杰克构建工具链。 I'm still not sure how to resolve this.
我还不确定如何解决这个问题。
I finally found the answer. 我终于找到了答案。
This issue is specific to using the jack toolchain and the Support Repository/Google Repository v46 . 此问题特定于使用jack工具链和Support Repository / Google Repository v46 。 When using version 45 of the Google Repository everything works great, but version 46 breaks the build for instrumented tests.
使用Google Repository版本45时,一切都很好,但版本46打破了仪表化测试的构建。 I suppose this won't matter once AS 2.4 comes out with official support for Java 1.8.
我想,一旦AS 2.4出现了对Java 1.8的官方支持,这无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.