一、Android獲取所有依賴庫
第一種方式通過dependencies 獲取所有依賴庫
gradle :app:dependencies
輸出列表展示了所有configuration下的依賴樹,依賴關(guān)系明顯,層次清晰。
第二種方式獲取所有依賴庫
第一種方式輸出列表展示了所有configuration下的依賴樹,依賴關(guān)系明顯,層次清晰贱纠。如果覺得輸出的結(jié)果太冗長(通常情況下包含幾十個(gè)configuration),可以通過指定configuration來顯示特定的依賴樹
//該命令只會(huì)顯示release模式下編譯過程中的依賴樹响蕴。
gradle :app:dependencies --configuration releaseCompileClasspath
//該命令指定compile環(huán)境谆焊,查看依賴樹命令如下
gradle :app:dependencies --configuration compile
//如果日志太長可以寫入本地文件
gradle :app:dependencies --configuration debugCompileClasspath > log.txt
查看其他配置類型:
gradle dependencies --info
configuration配置默認(rèn)有以下類型,重點(diǎn)關(guān)注debugCompileClasspath和releaseCompileClasspath即可
debugAndroidTestCompileClasspath - Compile classpath for compilation 'debugAndroidTest' (target (androidJvm)).
debugCompileClasspath - Compile classpath for compilation 'debug' (target (androidJvm)).
debugUnitTestCompileClasspath - Compile classpath for compilation 'debugUnitTest' (target (androidJvm)).
releaseCompileClasspath - Compile classpath for compilation 'release' (target (androidJvm)).
releaseUnitTestCompileClasspath - Compile classpath for compilation 'releaseUnitTest' (target (androidJvm)).
注意:如果有flavor浦夷,則配置名會(huì)變辖试,例如Flavor為Xiaomi辜王,配置為:
XiaomiDebugAndroidTestCompileClasspath
XiaomiDebugCompileClasspath
XiaomiDebugUnitTestCompileClasspath
XiaomiReleaseCompileClasspath
XiaomiReleaseUnitTestCompileClasspath
第三種方式通過androidDependencies命令
gradle :app:androidDependencies
該task會(huì)平鋪展示依賴樹,并且只展示幾個(gè)主要的variant罐孝,看起來較為清爽呐馆,但是缺點(diǎn)是不能像方式一那樣指定configuration。
mac版命-令導(dǎo)出依賴到文件中
./gradlew app:dependencies >dependencies.txt
命令 gradle和./gradlew是相等的
gradle:app中的:app其實(shí)就是settings.gradle中對(duì)應(yīng)的module
gradlew:其實(shí)是gradle和 wrapper 的組合莲兢,縮寫為gradlew汹来。
第四種方式通過Android sutdio gradle task 工具
二、Android獲取所有依賴庫出現(xiàn)錯(cuò)誤
錯(cuò)誤一:
mac gradlew 命令 zsh: command not found: gradlew
解決方式:
chmod +x gradlew
注意:需要使用 ./gradlew
主要因?yàn)閙ac下執(zhí)行當(dāng)前目錄下的命令需要在前面加上“./”改艇,否則會(huì)到環(huán)境變量下找相應(yīng)命令收班。
錯(cuò)誤二:
然后可能出現(xiàn)
The operation couldn’t be completed. Unable to locate a Java Runtime.
解決方式:
在.bash_profile添加
export JAVA_HOME=/Applications/Android\Studio.app/Contents/jre/Contents/Home
然后terminal 輸入source .bash_profile
錯(cuò)誤三:
env: bash\r: No such file or directory
解決方法:
進(jìn)入項(xiàng)目目錄執(zhí)行下列命令即可:
brew install dos2unix
find . -type f -exec dos2unix {} \;
三、依賴關(guān)系
> Task :app:dependencies
------------------------------------------------------------
Project :app
------------------------------------------------------------
DebugCompileClasspath - Compile classpath for compilation 'Debug' (target (androidJvm)).
+--- androidx.databinding:viewbinding:4.0.1
| \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
+--- androidx.databinding:databinding-common:4.0.1
+--- androidx.databinding:databinding-runtime:4.0.1
| +--- androidx.databinding:viewbinding:4.0.1 (*)
| +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.5.1
| | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | +--- androidx.arch.core:core-common:2.1.0
| | | \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | \--- androidx.lifecycle:lifecycle-common:2.5.1
| | \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| +--- androidx.collection:collection:1.0.0 -> 1.1.0
| | \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| \--- androidx.databinding:databinding-common:4.0.1
+--- androidx.databinding:databinding-adapters:4.0.1
| +--- androidx.databinding:databinding-common:4.0.1
| \--- androidx.databinding:databinding-runtime:4.0.1 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31 -> 1.6.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.0 -> 1.7.10
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10
| | \--- org.jetbrains:annotations:13.0
| \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.0 -> 1.7.10 (*)
+--- project :business:drive
| +--- project :base
| | +--- androidx.core:core-ktx:1.6.0 -> 1.9.0
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | +--- androidx.core:core:1.9.0
| | | | +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
| | | | +--- androidx.annotation:annotation-experimental:1.3.0
| | | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 (*)
| | | | +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.5.1 (*)
| | | | \--- androidx.versionedparcelable:versionedparcelable:1.1.1
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 (*)
| | +--- com.google.android.material:material:1.2.1 -> 1.4.0
| | | +--- androidx.annotation:annotation:1.0.1 -> 1.3.0
| | | +--- androidx.appcompat:appcompat:1.1.0 -> 1.6.1
| | | | +--- androidx.activity:activity:1.6.0
| | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | | +--- androidx.core:core:1.8.0 -> 1.9.0 (*)
| | | | | +--- androidx.lifecycle:lifecycle-runtime:2.5.1 (*)
| | | | | +--- androidx.lifecycle:lifecycle-viewmodel:2.5.1
| | | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
| | | | | +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1
| | | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | | | +--- androidx.core:core-ktx:1.2.0 -> 1.9.0 (*)
| | | | | | +--- androidx.lifecycle:lifecycle-livedata-core:2.5.1
| | | | | | | \--- androidx.lifecycle:lifecycle-common:2.5.1 (*)
| | | | | | +--- androidx.lifecycle:lifecycle-viewmodel:2.5.1 (*)
| | | | | | +--- androidx.savedstate:savedstate:1.2.0
| | | | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.20 -> 1.7.10 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
| | | | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
| | | | | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
| | | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
| | | | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1 (c)
| | | | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1 (c)
| | | | | | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1 (c)
| | | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0 (*)
| | | | | | | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0 -> 1.7.10
| | | | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1 (*)
| | | | | | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0 (*)
| | | | | +--- androidx.savedstate:savedstate:1.2.0 (*)
| | | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 (*)
| | | | +--- androidx.annotation:annotation:1.3.0
| | | | +--- androidx.appcompat:appcompat-resources:1.6.1
| | | | | +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
| | | | | +--- androidx.core:core:1.6.0 -> 1.9.0 (*)
| | | | | +--- androidx.vectordrawable:vectordrawable:1.1.0
| | | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | | | +--- androidx.core:core:1.1.0 -> 1.9.0 (*)
| | | | | | \--- androidx.collection:collection:1.1.0 (*)
| | | | | \--- androidx.vectordrawable:vectordrawable-animated:1.1.0
| | | | | +--- androidx.vectordrawable:vectordrawable:1.1.0 (*)
| | | | | +--- androidx.interpolator:interpolator:1.0.0
| | | | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | | \--- androidx.collection:collection:1.1.0 (*)
| | | | +--- androidx.core:core:1.9.0 (*)
| | | | +--- androidx.cursoradapter:cursoradapter:1.0.0
| | | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | +--- androidx.drawerlayout:drawerlayout:1.0.0
| | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*)
| | | | | \--- androidx.customview:customview:1.0.0
| | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | | \--- androidx.core:core:1.0.0 -> 1.9.0 (*)
| | | | +--- androidx.fragment:fragment:1.3.6
| | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | | +--- androidx.core:core:1.2.0 -> 1.9.0 (*)
| | | | | +--- androidx.collection:collection:1.1.0 (*)
| | | | | +--- androidx.viewpager:viewpager:1.0.0
| | | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*)
| | | | | | \--- androidx.customview:customview:1.0.0 (*)
| | | | | +--- androidx.loader:loader:1.0.0
| | | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*)
| | | | | | +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.3.1
| | | | | | | +--- androidx.arch.core:core-runtime:2.1.0
| | | | | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | | | | | \--- androidx.arch.core:core-common:[2.1.0] -> 2.1.0 (*)
| | | | | | | \--- androidx.lifecycle:lifecycle-livedata-core:2.3.1 -> 2.5.1 (*)
| | | | | | \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.5.1 (*)
| | | | | +--- androidx.activity:activity:1.2.4 -> 1.6.0 (*)
| | | | | +--- androidx.lifecycle:lifecycle-livedata-core:2.3.1 -> 2.5.1 (*)
| | | | | +--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 -> 2.5.1 (*)
| | | | | +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1 -> 2.5.1 (*)
| | | | | +--- androidx.savedstate:savedstate:1.1.0 -> 1.2.0 (*)
| | | | | \--- androidx.annotation:annotation-experimental:1.0.0 -> 1.3.0 (*)
| | | | \--- androidx.savedstate:savedstate:1.2.0 (*)
| | | +--- androidx.cardview:cardview:1.0.0
| | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | +--- androidx.coordinatorlayout:coordinatorlayout:1.1.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | +--- androidx.core:core:1.1.0 -> 1.9.0 (*)
| | | | +--- androidx.customview:customview:1.0.0 (*)
| | | | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.constraintlayout:constraintlayout:2.0.1 -> 2.1.4
| | | +--- androidx.core:core:1.5.0 -> 1.9.0 (*)
| | | +--- androidx.dynamicanimation:dynamicanimation:1.0.0
| | | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*)
| | | | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | | \--- androidx.legacy:legacy-support-core-utils:1.0.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*)
| | | | +--- androidx.documentfile:documentfile:1.0.0
| | | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | +--- androidx.loader:loader:1.0.0 (*)
| | | | +--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
| | | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | \--- androidx.print:print:1.0.0
| | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.3.0 (*)
| | | +--- androidx.fragment:fragment:1.0.0 -> 1.3.6 (*)
| | | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.5.1 (*)
| | | +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.2.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | +--- androidx.core:core:1.3.2 -> 1.9.0 (*)
| | | | \--- androidx.customview:customview:1.0.0 (*)
| | | +--- androidx.transition:transition:1.2.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | | +--- androidx.core:core:1.0.1 -> 1.9.0 (*)
| | | | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.vectordrawable:vectordrawable:1.1.0 (*)
| | | \--- androidx.viewpager2:viewpager2:1.0.0
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | +--- androidx.fragment:fragment:1.1.0 -> 1.3.6 (*)
| | | +--- androidx.recyclerview:recyclerview:1.1.0 -> 1.2.0 (*)
| | | +--- androidx.core:core:1.1.0 -> 1.9.0 (*)
| | | \--- androidx.collection:collection:1.1.0 (*)
| | +--- androidx.appcompat:appcompat:1.3.0 -> 1.6.1 (*)
| | +--- androidx.constraintlayout:constraintlayout:2.0.4 -> 2.1.4
| | +--- androidx.recyclerview:recyclerview:1.2.0 (*)
| | +--- androidx.startup:startup-runtime:1.0.0 -> 1.1.1
| | +--- androidx.room:room-runtime:2.3.0
| | | +--- androidx.room:room-common:2.3.0
| | | | \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
| | | +--- androidx.sqlite:sqlite-framework:2.1.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | | \--- androidx.sqlite:sqlite:[2.1.0] -> 2.1.0
| | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | \--- androidx.sqlite:sqlite:2.1.0 (*)
| | +--- androidx.room:room-ktx:2.3.0
| | | +--- androidx.room:room-common:2.3.0 (*)
| | | +--- androidx.room:room-runtime:2.3.0 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 -> 1.7.10 (*)
| | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1 -> 1.6.1 (*)
| | +--- androidx.lifecycle:lifecycle-livedata-ktx:2.3.1
| | | +--- androidx.lifecycle:lifecycle-livedata:2.3.1 (*)
| | | +--- androidx.lifecycle:lifecycle-livedata-core-ktx:2.3.1
| | | | +--- androidx.lifecycle:lifecycle-livedata-core:2.3.1 -> 2.5.1 (*)
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.7.10 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.7.10 (*)
| | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1 -> 1.6.1 (*)
| | +--- androidx.lifecycle:lifecycle-runtime-ktx:2.5.0 -> 2.5.1
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | +--- androidx.lifecycle:lifecycle-runtime:2.5.1 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
| | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1 (*)
| | +--- androidx.lifecycle:lifecycle-service:2.3.1
| | | \--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.5.1 (*)
| | +--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1 -> 2.5.1
| | | +--- androidx.lifecycle:lifecycle-viewmodel:2.5.1 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
| | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1 (*)
| | +--- androidx.work:work-runtime-ktx:2.5.0
| | | +--- androidx.work:work-runtime:2.5.0
| | | | +--- com.google.guava:listenablefuture:1.0
| | | | \--- androidx.lifecycle:lifecycle-livedata:2.1.0 -> 2.3.1 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.21 -> 1.7.10 (*)
| | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1 -> 1.6.1 (*)
| | +--- com.squareup.retrofit2:retrofit:2.9.0
| | | \--- com.squareup.okhttp3:okhttp:3.14.9
| | | \--- com.squareup.okio:okio:1.17.2
| | +--- com.squareup.retrofit2:converter-gson:2.9.0
| | | +--- com.squareup.retrofit2:retrofit:2.9.0 (*)
| | | \--- com.google.code.gson:gson:2.8.5 -> 2.8.7
| | +--- com.squareup.okhttp3:okhttp:3.12.1 -> 3.14.9 (*)
| | +--- com.squareup.okhttp3:logging-interceptor:3.12.1
| | | \--- com.squareup.okhttp3:okhttp:3.12.1 -> 3.14.9 (*)
| | +--- com.google.code.gson:gson:2.8.7
| | +--- com.github.bumptech.glide:glide:4.12.0
| | | +--- com.github.bumptech.glide:gifdecoder:4.12.0
| | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
| | | +--- com.github.bumptech.glide:disklrucache:4.12.0
| | | +--- com.github.bumptech.glide:annotations:4.12.0
| | | +--- androidx.fragment:fragment:1.0.0 -> 1.3.6 (*)
| | | +--- androidx.vectordrawable:vectordrawable-animated:1.0.0 -> 1.1.0 (*)
| | | \--- androidx.exifinterface:exifinterface:1.2.0
| | | \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
符號(hào)的含義:
x.x.x () 該依賴已經(jīng)有了谒兄,將不再重復(fù)依賴摔桦。
x.x.x -> x.x.x 該依賴的版本被箭頭所指的版本代替。
x.x.x -> x.x.x() 該依賴的版本被箭頭所指的版本代替承疲,并且該依賴已經(jīng)有了邻耕,不再重復(fù)依賴。
三纪隙、解決依賴沖突
1、去除重復(fù)依賴
implementation (需要去掉重復(fù)包的第三方依賴){
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
2扛或、強(qiáng)制使用某一個(gè)版本
allprojects {
configurations.all {
resolutionStrategy {
force ‘com.google.code.gson:gson:2.9.0’
}
}
}
注意:并不能去除新增的版本