1. 程式人生 > >Android Studio 中 處理 Gradle 依賴的幾種方法的介紹

Android Studio 中 處理 Gradle 依賴的幾種方法的介紹

exclude

exclude : 剔除依賴中的某個模組
例:

// 根據組織名 + 構建名剔除

//recyclerview 不想要依賴 com.android.support:support-annotations:26.1.0,就可以這麼做
implementation ('com.android.support:recyclerview-v7:26.1.0'){
        exclude group: 'com.android.support', module: 'support-annotations'  
    }

//剔除 retrofit2 中的 okhttp3 模組    
implementation('com.squareup.retrofit2:retrofit:2.3.0') { exclude group: 'com.squareup.okhttp3' }

force

force : 強制指定依賴版本
**例,我想要所有 com.android.support:appcompat-v7:26.1.0 的依賴版本為 27.1.1 怎麼辦呢
在只需要在 build.gradle 中加上 force true 即可**

implementation("com.android.support:appcompat-v7:27.1.1"
){ force true }

transitive

transitive : 依賴傳遞特性,使用的時候,通常設定為 false 。即關閉依賴傳遞
例如專案中不希望 recyclerview 使用它所依賴的庫 :

implementation ('com.android.support:recyclerview-v7:27.1.1'){
        transitive  false
 }