最近,谷歌推出了Android 11的目标SDK版本33,并宣布从2021年8月1日开始将其强制执行。根据谷歌的要求,所有已在Google Play商店上跟踪的应用程序需要在该日期之前进行更新,否则将被否决。然而,许多开发人员似乎对DDL感到困惑,而且不知道如何正确设置目标SDK版本33。
以下是一个示例代码,展示如何正确设置目标SDK版本33:
android {
compileSdk 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.app"
minSdk 21
targetSdk 33 //设置目标SDK版本为33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
以上代码中,我们将目标SDK版本设置为33,这是满足Google Play商店更新要求的关键。建议所有开发人员立即更新应用程序,并及时测试以确保它们符合新的限制要求。