2017-08-20 23 views
1

我試圖使用的Mockito的儀器測試,當我添加androidTestCompile的Mockito givning錯誤

androidTestCompile 'org.mockito:mockito-core:2.7.22' 

我收到以下錯誤:

Error:Conflict with dependency 'org.objenesis:objenesis' in project ':app'. 
Resolved versions for app (2.1) and test app (2.5) differ. See 
http://g.co/androidstudio/app-test-app-conflict for details. 

我不知道什麼是錯的,我有沒有org.objenesis依賴指定在我的代碼中的任何地方(猜測它通過mockito來)。

每一個幫助,讚賞。

+0

沒有的Mockito應該是在你的'app',只有在你的'測試app'。你可以試試'./gradlew app:dependencies --configuration compile'並查看objenesis'是否在你的依賴圖中的任何位置? –

+0

我會檢查一下,它確實很奇怪,它可能包含在我一直使用的第三方庫中,因爲我從未將它包含在應用程序中。 – meow

回答

1

試試這個

configurations.all { resolutionStrategy { force 'org.objenesis:objenesis:2.1' } } 

就排除它在你的主項目。 exclude group: 'org.objenesis'

1

異常中的鏈接告訴你如何解決這個問題。

configurations.all { 
    resolutionStrategy { 
    force 'org.objenesis:objenesis:2.1.0' 
    } 
} 

否則,你可以使用:

androidTestCompile 'org.objenesis:objenesis:2.1.0' 
+1

感謝您的回答,但第二個選項,似乎並不適用於我。 – meow

相關問題