Android开发教程——jetpack的一些依赖,建议收藏!!!

导航

  dependencies {
        def activity_version = "1.2.0-rc01"

    // Java language implementation
    implementation "androidx.activity:activity:$activity_version"
    // Kotlin
    implementation "androidx.activity:activity-ktx:$activity_version"

    implementation "androidx.fragment:fragment:1.3.0-rc01"

    implementation "androidx.fragment:fragment-ktx:1.3.0-rc01"
    }

在1.2版本之后舍弃了之前的startActivityForResult而采用ActivityResult Api

dependencies {
  def nav_version = "2.3.2"

  // 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"

  // Feature module Support
  implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"

  // Testing Navigation
  androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"

  // Jetpack Compose Integration
  implementation "androidx.navigation:navigation-compose:1.0.0-alpha04"
}


生物识别以及身份认证

dependencies {
    // Java language implementation
    implementation "androidx.biometric:biometric:1.0.1"

    // Kotlin
    implementation "androidx.biometric:biometric:1.2.0-alpha01"
  }


由于并非所有的设备都会有生物识别的硬件,所以需要不同情况不同分析。
相机
--

dependencies {
  // CameraX core library using the camera2 implementation
  def camerax_version = "1.0.0-rc01"
  // The following line is optional, as the core library is included indirectly by camera-camera2
  implementation "androidx.camera:camera-core:${camerax_version}"
  implementation "androidx.camera:camera-camera2:${camerax_version}"
  // If you want to additionally use the CameraX Lifecycle library
  implementation "androidx.camera:camera-lifecycle:${camerax_version}"
  // If you want to additionally use the CameraX View class
  implementation "androidx.camera:camera-view:1.0.0-alpha20"
  // If you want to additionally use the CameraX Extensions library
  implementation "androidx.camera:camera-extensions:1.0.0-alpha20"
}

一些依赖

implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.0"
implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
implementation "androidx.drawerlayout:drawerlayout:1.1.1"
api "androidx.multidex:multidex:2.0.1"
kapt 'androidx.annotation:annotation:1.2.0'
api "com.google.android.material:material:1.3.0"


//动画差值器
implementation "androidx.interpolator:interpolator:1.0.0"
//app startup
implementation "androidx.startup:startup-runtime:1.0.0"
//一个库开发者,并且使用了ContentProvider的方式来进行初始化操作,那么你应该接入App Startup,这样可以让接入你的库的App降低启动耗时。

//读取和写入图片文件 EXIF 标记。
 implementation "androidx.exifinterface:exifinterface:1.3.2"

//查看文件文档
implementation "androidx.documentfile:documentfile:1.0.1"

//下拉刷新
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

//viewpager2
implementation "androidx.viewpager2:viewpager2:1.0.0"
//兼容window,以折叠屏为目标
implementation "androidx.window:window:1.0.0-alpha01"
//web
implementation "androidx.webkit:webkit:1.4.0"

//侧滑窗口
implementation "androidx.slidingpanelayout:slidingpanelayout:1.1.0"


dependencies {
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    // For control over item selection of both touch and mouse driven selection
    implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc03"
}

//降低现有和新的小型集合对内存的影响。
dependencies {
        def collection_version = "1.1.0"

        // Java language implementation
        implementation "androidx.collection:collection:$collection_version"
        // Kotlin
        implementation "androidx.collection:collection-ktx:$collection_version"
    }
    
    
    
dependencies {
    def core_version = "1.3.2"

    // 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-rc01"

    // To use the Animator APIs
    implementation "androidx.core:core-animation:1.0.0-alpha02"
    // To test the Animator APIs
    androidTestImplementation "androidx.core:core-animation-testing:1.0.0-alpha02"
}


dependencies {
    def fragment_version = "1.2.5"

    // Java language implementation
    implementation "androidx.fragment:fragment:$fragment_version"
    // Kotlin
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    // Testing Fragments in Isolation
    debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
}


DataStore

类型化

// Typed DataStore (Typed API surface, such as Proto)
dependencies {
  implementation "androidx.datastore:datastore:1.0.0-alpha05"
}
// Alternatively - use the following artifact without an Android dependency.
dependencies {
  implementation "androidx.datastore:datastore-core:1.0.0-alpha05"
}

偏好设置化

// Preferences DataStore (SharedPreferences like APIs)
dependencies {
  implementation "androidx.datastore:datastore-preferences:1.0.0-alpha05"
}
// Alternatively - use the following artifact without an Android dependency.
dependencies {
  implementation "androidx.datastore:datastore-preferences-core:1.0.0-alpha05"
}

使用物理特性制作流畅动画

dependencies {
        // Java language implementation
        implementation "androidx.dynamicanimation:dynamicanimation:1.0.0"

        // Kotlin
        implementation "androidx.dynamicanimation:dynamicanimation-ktx:1.0.0-alpha03"
    }

lifeCycle

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"
}

加载器

dependencies {
        implementation "androidx.loader:loader:1.1.0"
    }

Media2

没有官方文档
与其他应用共享媒体内容和控件。

dependencies {
    def media2_version = "1.1.1"

    // Interacting with MediaSessions
    implementation "androidx.media2:media2-session:$media2_version"
    // optional - UI widgets for VideoView and MediaControlView
    implementation "androidx.media2:media2-widget:$media2_version"
    // optional - Implementation of a SessionPlayer
    implementation "androidx.media2:media2-player:$media2_version"
}

Mediarouter

利用通用界面实现在远程接收端设备上显示和播放媒体内容。

dependencies {
    implementation "androidx.mediarouter:mediarouter:1.2.0"
}

paging 3

dependencies {
  def paging_version = "3.0.0-alpha11"

  implementation "androidx.paging:paging-runtime:$paging_version"

  // alternatively - without Android dependencies for tests
  testImplementation "androidx.paging:paging-common:$paging_version"

  // optional - RxJava2 support
  implementation "androidx.paging:paging-rxjava2:$paging_version"

  // optional - RxJava3 support
  implementation "androidx.paging:paging-rxjava3:$paging_version"

  // optional - Guava ListenableFuture support
  implementation "androidx.paging:paging-guava:$paging_version"

  // Jetpack Compose Integration
  implementation "androidx.paging:paging-compose:1.0.0-alpha04"
}

room

dependencies {
  def room_version = "2.2.5"

  implementation "androidx.room:room-runtime:$room_version"
  kapt "androidx.room:room-compiler:$room_version"

  // optional - Kotlin Extensions and Coroutines support for Room
  implementation "androidx.room:room-ktx:$room_version"

  // optional - Test helpers
  testImplementation "androidx.room:room-testing:$room_version"
}

sqlist

 dependencies {
        def sqlite_version = "2.1.0"

        // Java language implementation
        implementation "androidx.sqlite:sqlite:$sqlite_version"

        // Kotlin
        implementation "androidx.sqlite:sqlite-ktx:$sqlite_version"

        // Implementation of the AndroidX SQLite interfaces via the Android framework APIs.
        implementation "androidx.sqlite:sqlite-framework:$sqlite_version"
    }
    

Vectordrawable

渲染矢量图标

dependencies {
    implementation "androidx.vectordrawable:vectordrawable:1.1.0"

    /* To be able to animate properties of a VectorDrawable, add the following.  Useful for
     * illustration purposes or state changes in response to user events
     */
    implementation "androidx.vectordrawable:vectordrawable-animated:1.1.0"

    /* To use a seekable alternative for `androidx.vectordrawable:vectordrawable-animated` add the
     * following
     */
     implementation "androidx.vectordrawable:vectordrawable-seekable:1.0.0-alpha02"
}

work

dependencies {
  def work_version = "2.4.0"

    // (Java only)
    implementation "androidx.work:work-runtime:$work_version"

    // Kotlin + coroutines
    implementation "androidx.work:work-runtime-ktx:$work_version"

    // optional - RxJava2 support
    implementation "androidx.work:work-rxjava2:$work_version"

    // optional - GCMNetworkManager support
    implementation "androidx.work:work-gcm:$work_version"

    // optional - Test helpers
    androidTestImplementation "androidx.work:work-testing:$work_version"
  }

hilt

dependencies {

    api "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    api 'androidx.hilt:hilt-work:1.0.0-alpha03'
   // When using Kotlin.
    kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha03'

    api "com.google.dagger:hilt-android:2.28-alpha"
    kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
}

注意:在某些依赖中会包含了java和kotlin两种(标注了 java only的),请根据语言环境选择使用。

你可能感兴趣的:(Android开发教程——jetpack的一些依赖,建议收藏!!!)