1. 程式人生 > >Resolved versions for app (25.4.0) and test app (27.1.1) differ.

Resolved versions for app (25.4.0) and test app (27.1.1) differ.

嘿嘿來更博了開心~

剛剛遇到一個小問題,提示是這樣的:

WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (25.4.0) and test app (27.1.1) differ.

翻譯過來是說:

警告:與依賴項“com.android.support:support-annotations”衝突。解決版本的應用程式(25.4.0)和測試應用程式(27.1.1)不同。

專業術語叫依賴衝突,就是指測試版本和執行版本不一致,百度找到兩種寫法(都是一個意思就是不同形式而已,都可以解決問題)

寫法一:

(這句話可以寫在 defaultConfig {}裡也可以寫在 dependencies {}裡,效果一樣)

configurations.all {
            resolutionStrategy.force 'com.android.support:support-annotations:25.4.0'//強制用25.4.0的配置
        }

寫法二:

(這句話寫在 dependencies {}裡才有效,寫在defaultConfig {}裡不起作用,具體原因沒研究)

androidTestCompile('com.android.support:support-annotations:25.4.0') {
        force 
= true }

以上提到的force是強制的意思,指“強制設定某個模組的版本”,個人建議使用寫法一。

希望看到這篇文章的你解決了該問題~