2017-04-20 101 views
1

我一直在关注android testing codelab并试图以类似的方式建模我的应用程序。这样做并没有消除所有这一切。当我尝试运行/构建Android测试时,在使用支持库类(如AppCompatActivity和TextInputLayout)时出现错误。错误说:建设Android仪器测试

The type android.support.design.widget.TextInputLayout cannot be found in source files, imported jack libs or the classpath 

我跑./gradlew app:dependencies,事实上这些都没有在classpath中发现:

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的支持库,但构建本身仍然失败,并出现相同的错误。

不幸的是我无法发布整个代码。有没有人遇到过这样的事情?任何想法如何解决这个问题?

UPDATE:

为了澄清,一切都定期调试和发布版本中的伟大工程。只有在运行androidTest构建时,我会看到这个错误。

更新2:

问题似乎是围绕插孔构建工具链。我仍然不确定如何解决这个问题。

+0

你是否在'dependencies'块中声明'compile'c​​om.android.support:design:25.3.1''? – Egor

+0

是的,我会更新包括这些。该应用程序构建并运行100%。所以我也可以访问com.android.support:appcompat-v7:25.3.1 – TheHebrewHammer

回答

0

我终于找到了答案。

此问题是特定于使用插孔工具链和支持存储库/谷歌库V46。使用Google Repository版本45时,一切都很好,但是版本46打破了仪表测试的构建。一旦AS 2.4发布官方支持Ja​​va 1.8,我想这不会有问题。