1

我想为我的应用程序设置一个Instrumented Unit Tests。并且我已经添加了基于以下开发者网站链接的依赖关系。与依赖冲突'com.android.support:support-annotations'

https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html#build

这是我的依赖列表

dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
    compile 'com.android.support:support-v4:21.0.3' 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.10.19' 
    androidTestCompile 'com.android.support:support-annotations:24.0.0' 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support.test:rules:0.5' 
} 

当我建立我得到下面的编译错误的项目:

Error:Conflict with dependency 'com.android.support:support-annotations' in project ':MyApp'. Resolved versions for the app (21.0.3) and test app (24.0.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details. 

任何人都可以请帮我解决这个问题。

回答

3

注解是支持库的一部分。所以,你的注释和支持库的版本应该是相同的,你必须使用下面的代码强行调用。这代码应该放在上面dependencies.For详细 See here

configurations.all { 
    resolutionStrategy { 
    force 'com.android.support:support-annotations:21.0.3' 
    } 
} 
+0

我已经更改为21.0.3,现在我获取此错误错误:与项目':MyApp'中的依赖项'com.android.support:support-annotations'冲突。应用程序(21.0.3)和测试应用程序(23.1.1)的已解决版本不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。 – Vji

+0

谢谢Priya ... – Vji

+0

欢迎光临:) –