2017-04-18 83 views
0

我想在现有项目中设置androidTests。Android设置androidTestCompile

继谷歌官方指导我添加以下的依赖:

androidTestCompile 'junit:junit:4.12' 
    androidTestCompile 'org.robolectric:robolectric:3.1.2' 
    androidTestCompile 'org.assertj:assertj-core:3.5.2' 
    androidTestCompile 'com.android.support:support-annotations: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', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3' 

的第一个问题是,认为有在APK中的多个confilicting文件(一式两份):

packagingOptions { 
     pickFirst '.readme' 
     pickFirst 'META-INF/LICENSE.txt' 
     pickFirst 'META-INF/plexus/components.xml' 
     pickFirst 'META-INF/NOTICE.txt' 
     pickFirst 'META-INF/MANIFEST.MF' 
     pickFirst 'licenses/thoughtworks.TXT' 
     pickFirst 'licenses/javolution.license.TXT' 
     pickFirst 'licenses/extreme.indiana.edu.license.TXT' 
     pickFirst 'org/apache/maven/project/pom-4.0.0.xml' 
     pickFirst 'org/codehaus/plexus/plexus-bootstrap.xml' 
     pickFirst 'org/cyberneko/html/res/HTMLlat1.properties' 
     pickFirst 'org/cyberneko/html/res/HTMLsymbol.properties' 
     pickFirst 'org/cyberneko/html/res/XMLbuiltin.properties' 
     pickFirst 'org/cyberneko/html/res/HTMLspecial.properties' 
     pickFirst 'org/cyberneko/html/res/ErrorMessages_ja.properties' 
     pickFirst 'org/cyberneko/html/res/ErrorMessages.properties' 
     pickFirst 'org/cyberneko/html/res/ErrorMessages_ja.txt' 
     pickFirst 'org/cyberneko/html/res/ErrorMessages.txt' 
     pickFirst 'META-INF/LICENSE' 
     pickFirst 'META-INF/DEPENDENCIES' 
    } 

排除后重复的,我结束了约1700警告关于类,超类和界面哪些找不到,以及错误:

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForMediadeDebugAndroidTest'. 
> Job failed, see logs for details 

我真的不知道要在哪些部分进一步查看,以使测试工作。

编辑:这里是Gradle Logs

+0

请从**摇篮控制台分享日志**。 –

+0

https://gist.githubusercontent.com/4ndro1d/92c7f210fa6dddf48feb63a75529eaad/raw/4de36bd98e274b7726d03fd539306649b30f4555/Gradle%2520Log希望此链接有效 – 4ndro1d

+0

您发布的日志似乎没有任何*错误*。看来你正在使用ProGuard进行测试?为什么要在运行测试时这么做? –

回答

1

在运行测试你不必运行ProGuard的,这样你就可以删除proguardFiles线,改变minifyEnabled

编辑

为了摆脱重复的依赖关系,你需要检查摇篮控制台日志,查找线路约java.util.zip.ZipException: duplicate entry找到哪些类被添加多次。

一旦你知道哪些类是重复的,你可以修复它按如下说明:Fixing ZipException: duplicate entry

+0

如何知道从哪个依赖关系生成重复项?我是否需要删除所有依赖关系,然后再次添加它们?有没有更好的解决方案? – 4ndro1d

+0

你也许可以搜索你在错误中看到的类名,并找出它必须来自哪个依赖项...... –

+0

这就是我要做的。通常,当你只是添加一个依赖关系而无法构建时就会知道它。 –