使用Gradle檢視Android專案中庫的依賴關係

小編發表於2019-03-04

Terminal中,可以通過 gradle 的命令檢視專案中所使用庫的版本,並且可以更加直觀看到庫之間的依賴關係。同時它們可以幫助您跟蹤並解決與庫版本衝突有關的任何問題。Building Android apps


工具檢視

  1. 在AndroidStudio中選擇 View > Tool Windows > Gradle
    或者直接選擇Gradle工具欄
  2. 展開 AppName > Tasks > android,雙擊androidDependencies.
  3. 選擇View > Tool Windows > Gradle Console,檢視輸出的日誌

dependencies

指令

$ ./gradlew :app:dependencies –configuration compile

說明
Window系統下,無需使用./開頭,直接使用gradlew即可。
執行app模組下的dependencies任務;額外配置compile,編譯環境下的依賴項。

結果

:app:dependencies

------------------------------------------------------------
Project :app
------------------------------------------------------------

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:25.3.1
|    +--- com.android.support:support-annotations:25.3.1
|    +--- com.android.support:support-v4:25.3.1
|    |    +--- com.android.support:support-compat:25.3.1
|    |    |    --- com.android.support:support-annotations:25.3.1
|    |    +--- com.android.support:support-media-compat:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    --- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-core-utils:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    --- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-core-ui:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    --- com.android.support:support-compat:25.3.1 (*)
|    |    --- com.android.support:support-fragment:25.3.1
|    |         +--- com.android.support:support-compat:25.3.1 (*)
|    |         +--- com.android.support:support-media-compat:25.3.1 (*)
|    |         +--- com.android.support:support-core-ui:25.3.1 (*)
|    |         --- com.android.support:support-core-utils:25.3.1 (*)
|    +--- com.android.support:support-vector-drawable:25.3.1
|    |    +--- com.android.support:support-annotations:25.3.1
|    |    --- com.android.support:support-compat:25.3.1 (*)
|    --- com.android.support:animated-vector-drawable:25.3.1
|         --- com.android.support:support-vector-drawable:25.3.1 (*)
+--- com.android.support:support-v4:25.3.1 (*)
+--- com.android.support:recyclerview-v7:25.3.1
|    +--- com.android.support:support-annotations:25.3.1
|    +--- com.android.support:support-compat:25.3.1 (*)
|    --- com.android.support:support-core-ui:25.3.1 (*)
+--- com.android.support:design:25.3.1
|    +--- com.android.support:support-v4:25.3.1 (*)
|    +--- com.android.support:appcompat-v7:25.3.1 (*)
|    +--- com.android.support:recyclerview-v7:25.3.1 (*)
|    --- com.android.support:transition:25.3.1
|         +--- com.android.support:support-annotations:25.3.1
|         --- com.android.support:support-v4:25.3.1 (*)
+--- com.yqritc:recyclerview-flexibledivider:1.2.9
+--- com.belerweb:pinyin4j:2.5.0
+--- com.j256.ormlite:ormlite-android:5.0
|    --- com.j256.ormlite:ormlite-core:5.0
+--- com.j256.ormlite:ormlite-core:5.0
+--- com.alibaba:arouter-api:1.2.1.1
|    +--- com.alibaba:arouter-annotation:1.0.3
|    --- com.android.support:support-v4:25.2.0 -> 25.3.1 (*)
+--- pub.devrel:easypermissions:0.4.0
+--- com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18
+--- com.afollestad.material-dialogs:core:0.9.4.5
|    +--- com.android.support:support-v13:25.3.1
|    |    +--- com.android.support:support-annotations:25.3.1
|    |    --- com.android.support:support-v4:25.3.1 (*)
|    +--- com.android.support:appcompat-v7:25.3.1 (*)
|    +--- com.android.support:recyclerview-v7:25.3.1 (*)
|    +--- com.android.support:support-annotations:25.3.1
|    --- me.zhanghai.android.materialprogressbar:library:1.4.1
|         +--- com.android.support:appcompat-v7:25.3.1 (*)
|         --- com.android.support:support-annotations:25.3.1
+--- com.alibaba:fastjson:1.2.32
--- com.esri.arcgis.android:arcgis-android:10.2.9

(*) - dependencies omitted (listed previously)

BUILD SUCCESSFUL

Total time: 11.69 secs複製程式碼

從中可以發現44行:com.alibaba:arouter-api:1.2.1.1依賴的support-v4庫版本比當前環境版本低,因此可以使用exclude剔除舊版本庫,避免衝突。

compile(`com.alibaba:arouter-api:1.2.1.1`) {
        exclude module: `support-v4`
}複製程式碼

dependencyInsight

指令

$ ./gradlew :app:dependencyInsight –dependency fastjson –configuration compile

說明
檢視指定庫的依賴關係

結果

:app:dependencyInsight
com.android.support:support-annotations:25.3.1
+--- com.afollestad.material-dialogs:core:0.9.4.5
|    --- compile
+--- com.android.support:appcompat-v7:25.3.1
|    +--- compile
|    +--- com.android.support:design:25.3.1
|    |    --- compile
|    +--- com.afollestad.material-dialogs:core:0.9.4.5 (*)
|    --- me.zhanghai.android.materialprogressbar:library:1.4.1
|         --- com.afollestad.material-dialogs:core:0.9.4.5 (*)
+--- com.android.support:recyclerview-v7:25.3.1
|    +--- compile
|    +--- com.android.support:design:25.3.1 (*)
|    --- com.afollestad.material-dialogs:core:0.9.4.5 (*)
+--- com.android.support:support-compat:25.3.1
|    +--- com.android.support:support-v4:25.3.1
|    |    +--- compile
|    |    +--- com.android.support:appcompat-v7:25.3.1 (*)
|    |    +--- com.android.support:design:25.3.1 (*)
|    |    +--- com.alibaba:arouter-api:1.2.1.1
|    |    |    --- compile
|    |    +--- com.android.support:transition:25.3.1
|    |    |    --- com.android.support:design:25.3.1 (*)
|    |    --- com.android.support:support-v13:25.3.1
|    |         --- com.afollestad.material-dialogs:core:0.9.4.5 (*)
|    +--- com.android.support:recyclerview-v7:25.3.1 (*)
|    +--- com.android.support:support-vector-drawable:25.3.1
|    |    +--- com.android.support:appcompat-v7:25.3.1 (*)
|    |    --- com.android.support:animated-vector-drawable:25.3.1
|    |         --- com.android.support:appcompat-v7:25.3.1 (*)
|    +--- com.android.support:support-media-compat:25.3.1
|    |    +--- com.android.support:support-v4:25.3.1 (*)
|    |    --- com.android.support:support-fragment:25.3.1
|    |         --- com.android.support:support-v4:25.3.1 (*)
|    +--- com.android.support:support-core-utils:25.3.1
|    |    +--- com.android.support:support-v4:25.3.1 (*)
|    |    --- com.android.support:support-fragment:25.3.1 (*)
|    +--- com.android.support:support-core-ui:25.3.1
|    |    +--- com.android.support:support-v4:25.3.1 (*)
|    |    +--- com.android.support:recyclerview-v7:25.3.1 (*)
|    |    --- com.android.support:support-fragment:25.3.1 (*)
|    --- com.android.support:support-fragment:25.3.1 (*)
+--- com.android.support:support-core-ui:25.3.1 (*)
+--- com.android.support:support-core-utils:25.3.1 (*)
+--- com.android.support:support-media-compat:25.3.1 (*)
+--- com.android.support:support-v13:25.3.1 (*)
+--- com.android.support:support-vector-drawable:25.3.1 (*)
+--- com.android.support:transition:25.3.1 (*)
--- me.zhanghai.android.materialprogressbar:library:1.4.1 (*)

(*) - dependencies omitted (listed previously)

BUILD SUCCESSFUL

Total time: 13.388 secs複製程式碼

相關文章