快速查看Gradle项目的类库依赖情况
Gradle項目中,導入依賴包和并對其管理是開發人員繞不開的事情,在導入的過程中,一不小心就會遇到新導入的依賴庫和原有的類庫沖突的問題,我在之前的一篇文章遇到異常Multiple dex files define時里提供了解決方法。本文對如何定位依賴沖突這個環節提供更多的方法
##方式1
./gradlew 模塊名:dependencies 復制代碼這個命令會打印出該模塊下的所有第三方類庫的依賴情況,有多種展示情況,complie編譯時的,Runtime運行時(打到APK包時)的,debug下,release下。
如下展示的是debugCompileClasspath即debug編譯時的引包情況:
debugCompileClasspath - Resolved configuration for compilation for variant: debug +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.31 | \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.31 | \--- org.jetbrains:annotations:13.0 +--- com.android.support:appcompat-v7:27.1.1 | +--- com.android.support:support-annotations:27.1.1 | +--- com.android.support:support-core-utils:27.1.1 | | +--- com.android.support:support-annotations:27.1.1 | | \--- com.android.support:support-compat:27.1.1 | | +--- com.android.support:support-annotations:27.1.1 | | \--- android.arch.lifecycle:runtime:1.1.0 | | +--- android.arch.lifecycle:common:1.1.0 | | \--- android.arch.core:common:1.1.0 | +--- com.android.support:support-fragment:27.1.1 | | +--- com.android.support:support-compat:27.1.1 (*) | | +--- com.android.support:support-core-ui:27.1.1 | | | +--- com.android.support:support-annotations:27.1.1 | | | +--- com.android.support:support-compat:27.1.1 (*) | | | \--- com.android.support:support-core-utils:27.1.1 (*) | | +--- com.android.support:support-core-utils:27.1.1 (*) | | +--- com.android.support:support-annotations:27.1.1 | | +--- android.arch.lifecycle:livedata-core:1.1.0 | | | +--- android.arch.lifecycle:common:1.1.0 | | | +--- android.arch.core:common:1.1.0 | | | \--- android.arch.core:runtime:1.1.0 | | | \--- android.arch.core:common:1.1.0 | | \--- android.arch.lifecycle:viewmodel:1.1.0 | +--- com.android.support:support-vector-drawable:27.1.1 | | +--- com.android.support:support-annotations:27.1.1 | | \--- com.android.support:support-compat:27.1.1 (*) | \--- com.android.support:animated-vector-drawable:27.1.1 | +--- com.android.support:support-vector-drawable:27.1.1 (*) | \--- com.android.support:support-core-ui:27.1.1 (*) \--- com.android.support.constraint:constraint-layout:1.0.2\--- com.android.support.constraint:constraint-layout-solver:1.0.2 復制代碼分層展示,不僅展示了該模塊下每個類庫的名稱、版本號,還展示了各類庫里所需依賴的類庫。 ##方式2 如果你嫌命令行麻煩,還有鼠標操作的方式
鼠標雙擊即可運行
其實方式一的命令行執行的就是截圖里dependencies任務。
Gradle項目構建的過程就是依次執行完所有任務的過程。
##方式3 如果你嫌在命令行窗口展示觀看不友好,這里還有一種體驗更好的方式。
輸入下面命令行:
./gradlew build --scan 復制代碼出現如下:
Publishing a build scan to scans.gradle.com requires accepting the Terms of Service defined at https://scans.gradle.com/terms-of-service. Do you accept these terms? [yes, no] 復制代碼輸入yes同意,將會出現一個網頁地址,登錄該網址。
該網頁還提供沖突提示,列出了引用了此類庫的類庫,效果如下
##小結 方式1和方式2實際上是同一種方法,方式3借助了Gradle官網為我們提供了視覺上更友好的查看包依賴。當編譯出現包依賴沖突的問題時,使用這種方式能極大的提高我們快速定位問題來源的效率。
###參考資料
Get started with build scans
總結
以上是生活随笔為你收集整理的快速查看Gradle项目的类库依赖情况的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HttpContext 来源(Syste
- 下一篇: HAproxy Json日志格式配置