Android 中支持旧版 API 的方法(API 30)(不适用,Android 向下兼容,故API可设置为最新的)

Android 中最新依赖库的版本支持 API 31 及以上版本,若要支持 API30,则对应的依赖库的版本就需要使用旧版本。
可通过修改模块级 build.gradle 文件来进行适配。

1、android 标签的 targetSdk 和 compileSdk 版本号

根据实际目标设备的 android 版本来确定版本号,这里设备是 Android 11 版本的,故将targetSdk 和 compileSdk 设置为 30。

android {
    namespace 'com.example.helloworld'
    compileSdk 30

    defaultConfig {
        applicationId "com.example.helloworld"
        minSdk 23
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
}

2、dependencies 标签中修改依赖库版本

dependencies {
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.annotation:annotation:1.3.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
	
	// 协程 lifecycleScope
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
}

3、查询依赖库旧版本号

可在官网上查询某个依赖库的旧版本号信息。
网站:https://developer.android.google.cn/jetpack/androidx/explorer

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值