我一直关注android testing 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()}"
}
}
请注意直接从codelab获取的configurations.all
和configurations.compile
。我尝试将支持库添加为androidTestCompile
依赖项,但似乎什么也没做。当我删除configurations.compile
块时,我可以在androidTestCompile
的依赖关系树中看到支持库,但构建本身仍然失败并出现相同的错误。
不幸的是我无法发布整个代码。有没有人碰到这样的事情?有关如何解决此问题的任何想法?
更新
为了澄清,在常规调试和发布版本中,一切都很有效。只有在运行androidTest版本时才会看到此错误。
更新2:
问题似乎是杰克构建工具链。我仍然不确定如何解决这个问题。
答案 0 :(得分:0)
我终于找到了答案。
此问题特定于使用 jack 工具链和支持存储库/ Google存储库v46 。使用Google Repository版本45时,一切都很好,但版本46打破了仪表化测试的构建。我想,一旦AS 2.4出现了对Java 1.8的官方支持,这就不重要了。