com.android.support衝突的解決辦法

來源:互聯網
上載者:User

標籤:version   表示   ring   ash   項目   使用   解決   support   provided   

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes

當我們使用android studio添加一些第三方的依賴庫時,很可能會提示上面這個錯誤。

大致意思就是com.android.support的包版本號碼要保持一致,但是可能我們自己建立的項目的com.android.support包版本號碼要高一些,一些第三方的庫的com.android.support可能沒有及時更新support庫,就會出現這個錯誤。

解決方案(同樣的適用於其他的依賴衝突。) 
1)修改自己項目中的com.android.support的版本號碼,與所依賴的庫版本號碼一致,但是當我們依賴的庫中的com.android.support版本號碼有好幾個版本就不行了。(不推薦)

2)推薦這種方法,如果發生衝突了,依賴第三方庫時候排除掉對com.android.support包的依賴,這樣自己的項目隨便依賴什麼版本都可以。

group:表示只要包含com.android.support的都排除 
api是android studio3.0中新的依賴方式,對依賴方式還不熟悉的話可以看這篇文章:Android Studio3.0新的依賴方式

例如:

    api("衝突的依賴") {        exclude group: ‘com.android.support‘    }

module:刪排除group中的指定module 
例如:

    api("衝突的依賴") {        exclude group: ‘com.android.support‘, module: ‘support-v13‘        exclude group: ‘com.android.support‘, module: ‘support-vector-drawable‘    }

另外還有一個建議,在我們自己建立library給別人使用時,如果需要依賴com.android.support的話,建議用provided的方式依賴(android studio3.0中更改為compileOnly),這樣只會在編譯時間有效,不會參與打包。以免給使用者帶來不便。

例:

    provided ‘com.android.support:appcompat-v7:26.1.0‘    provided ‘com.android.support:design:26.1.0‘    provided ‘com.android.support:support-vector-drawable:26.1.0‘

好了,就這些,希望能幫到你。

com.android.support衝突的解決辦法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.