快速查看Gradle项目的类库依赖情况
Gradle項(xiàng)目中,導(dǎo)入依賴包和并對(duì)其管理是開發(fā)人員繞不開的事情,在導(dǎo)入的過程中,一不小心就會(huì)遇到新導(dǎo)入的依賴庫和原有的類庫沖突的問題,我在之前的一篇文章遇到異常Multiple dex files define時(shí)里提供了解決方法。本文對(duì)如何定位依賴沖突這個(gè)環(huán)節(jié)提供更多的方法
##方式1
./gradlew 模塊名:dependencies 復(fù)制代碼這個(gè)命令會(huì)打印出該模塊下的所有第三方類庫的依賴情況,有多種展示情況,complie編譯時(shí)的,Runtime運(yùn)行時(shí)(打到APK包時(shí))的,debug下,release下。
如下展示的是debugCompileClasspath即debug編譯時(shí)的引包情況:
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 復(fù)制代碼分層展示,不僅展示了該模塊下每個(gè)類庫的名稱、版本號(hào),還展示了各類庫里所需依賴的類庫。 ##方式2 如果你嫌命令行麻煩,還有鼠標(biāo)操作的方式
鼠標(biāo)雙擊即可運(yùn)行
其實(shí)方式一的命令行執(zhí)行的就是截圖里dependencies任務(wù)。
Gradle項(xiàng)目構(gòu)建的過程就是依次執(zhí)行完所有任務(wù)的過程。
##方式3 如果你嫌在命令行窗口展示觀看不友好,這里還有一種體驗(yàn)更好的方式。
輸入下面命令行:
./gradlew build --scan 復(fù)制代碼出現(xiàn)如下:
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] 復(fù)制代碼輸入yes同意,將會(huì)出現(xiàn)一個(gè)網(wǎng)頁地址,登錄該網(wǎng)址。
該網(wǎng)頁還提供沖突提示,列出了引用了此類庫的類庫,效果如下
##小結(jié) 方式1和方式2實(shí)際上是同一種方法,方式3借助了Gradle官網(wǎng)為我們提供了視覺上更友好的查看包依賴。當(dāng)編譯出現(xiàn)包依賴沖突的問題時(shí),使用這種方式能極大的提高我們快速定位問題來源的效率。
###參考資料
Get started with build scans
總結(jié)
以上是生活随笔為你收集整理的快速查看Gradle项目的类库依赖情况的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HttpContext 来源(Syste
- 下一篇: HAproxy Json日志格式配置