在学习和使用
jetpack
组件时,总是被其 gradle 依赖搞的晕头转向,故在此整理jetpack
主要组件的依赖,及传递关系
jetpcak
组件源码地址jetpcak
组件 版本: Google’s Maven Repository./gradlew :app:dependencies
dependencies {
def appcompat_version = "1.1.0"
implementation "androidx.appcompat:appcompat:$appcompat_version"
// For loading and tinting drawables on older versions of the platform
implementation "androidx.appcompat:appcompat-resources:$appcompat_version"
}
+--- androidx.appcompat:appcompat:1.1.0
| +--- androidx.annotation:annotation:1.1.0
| +--- androidx.core:core:1.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.1.0
| | | +--- androidx.lifecycle:lifecycle-common:2.1.0
| | | | \--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.arch.core:core-common:2.1.0
| | | | \--- androidx.annotation:annotation:1.1.0
| | | \--- androidx.annotation:annotation:1.1.0
| | +--- androidx.versionedparcelable:versionedparcelable:1.1.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | \--- androidx.collection:collection:1.0.0 -> 1.1.0
| | | \--- androidx.annotation:annotation:1.1.0
| | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| +--- androidx.cursoradapter:cursoradapter:1.0.0
| | \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| +--- androidx.fragment:fragment:1.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.core:core:1.1.0 (*)
| | +--- androidx.collection:collection:1.1.0 (*)
| | +--- androidx.viewpager:viewpager:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | \--- androidx.customview:customview:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | | \--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | +--- androidx.loader:loader:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.lifecycle:lifecycle-livedata:2.0.0
| | | | +--- androidx.arch.core:core-runtime:2.0.0
| | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | | | | \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
| | | | +--- androidx.lifecycle:lifecycle-livedata-core:2.0.0
| | | | | +--- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.1.0 (*)
| | | | | +--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
| | | | | \--- androidx.arch.core:core-runtime:2.0.0 (*)
| | | | \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
| | | \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.1.0
| | | \--- androidx.annotation:annotation:1.1.0
| | +--- androidx.activity:activity:1.0.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.core:core:1.1.0 (*)
| | | +--- androidx.lifecycle:lifecycle-runtime:2.1.0 (*)
| | | +--- androidx.lifecycle:lifecycle-viewmodel:2.1.0 (*)
| | | \--- androidx.savedstate:savedstate:1.0.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.arch.core:core-common:2.0.1 -> 2.1.0 (*)
| | | \--- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.1.0 (*)
| | \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.1.0 (*)
| +--- androidx.appcompat:appcompat-resources:1.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.core:core:1.0.1 -> 1.1.0 (*)
| | +--- androidx.vectordrawable:vectordrawable:1.1.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.core:core:1.1.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.1.0
| | | \--- androidx.collection:collection:1.1.0 (*)
| | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| +--- androidx.drawerlayout:drawerlayout:1.0.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | \--- androidx.customview:customview:1.0.0 (*)
| \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
androidx.annotation:annotation:1.1.0
androidx.core:core:1.1.0
androidx.cursoradapter:cursoradapter:1.0.0
androidx.fragment:fragment:1.1.0
androidx.appcompat:appcompat-resources:1.1.0
androidx.drawerlayout:drawerlayout:1.0.0
androidx.collection:collection:1.0.0
appcompat
中默认引入了fragment
库,如果想使用更新版本的fragment
库,可以单独引用
appcompat build.gradle 源码地址
dependencies {
def fragment_version = "1.2.2"
// Java language implementation
implementation "androidx.fragment:fragment:$fragment_version"
// Kotlin
implementation "androidx.fragment:fragment-ktx:$fragment_version"
// Testing Fragments in Isolation
implementation "androidx.fragment:fragment-testing:$fragment_version"
}
⚠️ Note: The Kotlin dependant libraries of this version (fragment-ktx,fragment-testing) target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.
androidx.fragment:fragment-ktx:1.2.2
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
+--- androidx.fragment:fragment:[1.2.2] -> 1.2.2
| +--- androidx.annotation:annotation:1.1.0
| +--- androidx.core:core:1.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.2.0
| | | +--- androidx.lifecycle:lifecycle-common:2.2.0
| | | | \--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.arch.core:core-common:2.1.0
| | | | \--- androidx.annotation:annotation:1.1.0
| | | \--- androidx.annotation:annotation:1.1.0
| | +--- androidx.versionedparcelable:versionedparcelable:1.1.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | \--- androidx.collection:collection:1.0.0 -> 1.1.0
| | | \--- androidx.annotation:annotation:1.1.0
| | \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| +--- androidx.collection:collection:1.1.0 (*)
| +--- androidx.viewpager:viewpager:1.0.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | \--- androidx.customview:customview:1.0.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | \--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| +--- androidx.loader:loader:1.0.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | +--- androidx.core:core:1.0.0 -> 1.1.0 (*)
| | +--- androidx.lifecycle:lifecycle-livedata:2.0.0
| | | +--- androidx.arch.core:core-runtime:2.0.0 -> 2.1.0
| | | | +--- androidx.annotation:annotation:1.1.0
| | | | \--- androidx.arch.core:core-common:[2.1.0] -> 2.1.0 (*)
| | | +--- androidx.lifecycle:lifecycle-livedata-core:2.0.0 -> 2.2.0
| | | | +--- androidx.lifecycle:lifecycle-common:2.2.0 (*)
| | | | +--- androidx.arch.core:core-common:2.1.0 (*)
| | | | \--- androidx.arch.core:core-runtime:2.1.0 (*)
| | | \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
| | \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.2.0
| | \--- androidx.annotation:annotation:1.1.0
| +--- androidx.activity:activity:1.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.core:core:1.1.0 (*)
| | +--- androidx.lifecycle:lifecycle-runtime:2.2.0 (*)
| | +--- androidx.lifecycle:lifecycle-viewmodel:2.2.0 (*)
| | +--- androidx.savedstate:savedstate:1.0.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.arch.core:core-common:2.0.1 -> 2.1.0 (*)
| | | \--- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.2.0 (*)
| | \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0 -> 2.2.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | +--- androidx.savedstate:savedstate:1.0.0 (*)
| | +--- androidx.lifecycle:lifecycle-livedata-core:2.2.0 (*)
| | \--- androidx.lifecycle:lifecycle-viewmodel:2.2.0 (*)
| +--- androidx.lifecycle:lifecycle-livedata-core:2.2.0 (*)
| +--- androidx.lifecycle:lifecycle-viewmodel:2.2.0 (*)
| \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0 (*)
+--- androidx.activity:activity-ktx:1.1.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| +--- androidx.activity:activity:[1.1.0] -> 1.1.0 (*)
| +--- androidx.core:core-ktx:1.1.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.31 -> 1.3.61 (*)
| | +--- androidx.annotation:annotation:1.1.0
| | \--- androidx.core:core:1.1.0 (*)
| +--- androidx.lifecycle:lifecycle-runtime-ktx:2.2.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| | | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50 -> 1.3.61
| | +--- androidx.lifecycle:lifecycle-runtime:2.2.0 (*)
| | \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| \--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0 (*)
| \--- androidx.lifecycle:lifecycle-viewmodel:2.2.0 (*)
+--- androidx.core:core-ktx:1.1.0 (*)
+--- androidx.collection:collection-ktx:1.1.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.20 -> 1.3.61 (*)
| \--- androidx.collection:collection:1.1.0 (*)
+--- androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| \--- androidx.lifecycle:lifecycle-livedata-core:2.2.0 (*)
\--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0 (*)
org.jetbrains.kotlin:kotlin-stdlib:1.3.50
androidx.activity:activity-ktx:1.1.0
androidx.core:core-ktx:1.1.0
androidx.collection:collection-ktx:1.1.0
androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0
androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0
fragment
库默认引入了activity
core-ktx
lifecycle-livedata-core-ktx
lifecycle-viewmodel-ktx
库fragment build.grdle 源码地址
dependencies {
def activity_version = "1.1.0"
// Java language implementation
implementation "androidx.activity:activity:$activity_version"
// Kotlin
implementation "androidx.activity:activity-ktx:$activity_version"
}
⚠️ Note: The Kotlin dependant libraries of this version (activity-ktx) target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.
androidx.activity:activity-ktx:1.1.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
+--- androidx.activity:activity:[1.1.0] -> 1.1.0
| +--- androidx.annotation:annotation:1.1.0
| +--- androidx.core:core:1.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.2.0
| | | +--- androidx.lifecycle:lifecycle-common:2.2.0
| | | | \--- androidx.annotation:annotation:1.1.0
| | | +--- androidx.arch.core:core-common:2.1.0
| | | | \--- androidx.annotation:annotation:1.1.0
| | | \--- androidx.annotation:annotation:1.1.0
| | +--- androidx.versionedparcelable:versionedparcelable:1.1.0
| | | +--- androidx.annotation:annotation:1.1.0
| | | \--- androidx.collection:collection:1.0.0
| | | \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| | \--- androidx.collection:collection:1.0.0 (*)
| +--- androidx.lifecycle:lifecycle-runtime:2.2.0 (*)
| +--- androidx.lifecycle:lifecycle-viewmodel:2.2.0
| | \--- androidx.annotation:annotation:1.1.0
| +--- androidx.savedstate:savedstate:1.0.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.arch.core:core-common:2.0.1 -> 2.1.0 (*)
| | \--- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.2.0 (*)
| \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0
| +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| +--- androidx.savedstate:savedstate:1.0.0 (*)
| +--- androidx.lifecycle:lifecycle-livedata-core:2.2.0
| | +--- androidx.lifecycle:lifecycle-common:2.2.0 (*)
| | +--- androidx.arch.core:core-common:2.1.0 (*)
| | \--- androidx.arch.core:core-runtime:2.1.0
| | +--- androidx.annotation:annotation:1.1.0
| | \--- androidx.arch.core:core-common:[2.1.0] -> 2.1.0 (*)
| \--- androidx.lifecycle:lifecycle-viewmodel:2.2.0 (*)
+--- androidx.core:core-ktx:1.1.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.31 -> 1.3.61 (*)
| +--- androidx.annotation:annotation:1.1.0
| \--- androidx.core:core:1.1.0 (*)
+--- androidx.lifecycle:lifecycle-runtime-ktx:2.2.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50 -> 1.3.61
| +--- androidx.lifecycle:lifecycle-runtime:2.2.0 (*)
| \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
\--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.50 -> 1.3.61 (*)
+--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0 (*)
\--- androidx.lifecycle:lifecycle-viewmodel:2.2.0 (*)
org.jetbrains.kotlin:kotlin-stdlib:1.3.50
androidx.core:core-ktx:1.1.0
androidx.lifecycle:lifecycle-runtime-ktx:2.2.0
androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0
activity build.gradle 源码地址
dependencies {
def core_version = "1.2.0"
// Java language implementation
implementation "androidx.core:core:$core_version"
// Kotlin
implementation "androidx.core:core-ktx:$core_version"
// To use RoleManagerCompat
implementation "androidx.core:core-role:1.0.0-alpha01"
}
androidx.core:core-ktx:1.2.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.41
| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.41
| \--- org.jetbrains:annotations:13.0
+--- androidx.annotation:annotation:1.1.0
\--- androidx.core:core:1.2.0
+--- androidx.annotation:annotation:1.1.0
+--- androidx.lifecycle:lifecycle-runtime:2.0.0
| +--- androidx.lifecycle:lifecycle-common:2.0.0
| | \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| +--- androidx.arch.core:core-common:2.0.0
| | \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
| \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
+--- androidx.versionedparcelable:versionedparcelable:1.1.0
| +--- androidx.annotation:annotation:1.1.0
| \--- androidx.collection:collection:1.0.0
| \--- androidx.annotation:annotation:1.0.0 -> 1.1.0
\--- androidx.collection:collection:1.0.0 (*)
dependencies {
def lifecycle_version = "2.2.0"
def arch_version = "2.1.0"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
// optional - helpers for implementing LifecycleOwner in a Service
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
// optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
// optional - ReactiveStreams support for LiveData
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
// optional - Test helpers for LiveData
testImplementation "androidx.arch.core:core-testing:$arch_version"
}
- ⚠️
lifecycle-extensions
已废弃,如果使用LifecycleService
请依赖lifecycle-service
;如果使用ProcessLifecycleOwner
请依赖lifecycle-process
。lifecycle-extensionsl
不会有2.3.0版本- 2.1.0 后
ViewModelProviders.of()
被废弃。您可以在FragmentActivity
或者Fragment
使用ViewModelProvider(ViewModelStoreOwner)
构造器来实现相同的功能。(Fragment
库 1.2.0以上)
dependencies {
def nav_version = "2.3.0-alpha02"
// Java language implementation
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
// Dynamic Feature Module Support
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
}
dependencies {
def paging_version = "2.1.1"
implementation "androidx.paging:paging-runtime:$paging_version" // For Kotlin use paging-runtime-ktx
// alternatively - without Android dependencies for testing
testImplementation "androidx.paging:paging-common:$paging_version" // For Kotlin use paging-common-ktx
// optional - RxJava support
implementation "androidx.paging:paging-rxjava2:$paging_version" // For Kotlin use paging-rxjava2-ktx
}
dependencies {
def room_version = "2.2.4"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// Test helpers
testImplementation "androidx.room:room-testing:$room_version"
}
⚠️ Note: For Kotlin-based apps, make sure you use kapt instead of annotationProcessor. You should also add the kotlin-kapt plugin.
我是 Fy_with24