You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Android Studio中‘Not targeting the latest version of Android’警告

解决Android编译SDK更新后出现的"未针对最新Android版本"警告

问题描述

我把targetSdkVersion和compileSdkVersion更新到33时,发现compileSdkVersion已被废弃,于是改用compileSdk 33。但在模拟器运行应用时收到以下警告:

"Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details."

当前模块级build.gradle代码如下:

android {
    compileSdk 33
    defaultConfig {
        applicationId "com.wastefreemail.wfmconnect"
        minSdkVersion 16
        targetSdkVersion 33
        versionCode 17
        versionName "1.3.4"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    namespace 'com.wastefreemail.wfmconnect'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

解决方法

这个警告是因为当前使用的compileSdk和targetSdkVersion不是Android Gradle Plugin(AGP)识别的最新稳定版本,或项目存在版本不匹配情况,按以下步骤处理:

  • 同步更新到最新稳定Android SDK版本
    将compileSdk和targetSdkVersion统一替换为当前最新的稳定Android版本(例如当前最新稳定版为34):

    android {
        compileSdk 34
        defaultConfig {
            // 保留其他原有配置
            targetSdkVersion 34
            // 保留其他原有配置
        }
    }
    
  • 更新Android Gradle Plugin(AGP)版本
    确保AGP版本支持最新SDK,在项目级build.gradle或settings.gradle中更新到最新稳定版(例如8.2.0):

    // 项目级build.gradle示例
    plugins {
        id 'com.android.application' version '8.2.0' apply false
        id 'com.android.library' version '8.2.0' apply false
    }
    
  • 同步更新依赖库版本
    将核心依赖更新到适配最新SDK的稳定版本:

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.7.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.5'
        testImplementation 'junit:junit:4.13.2'
        androidTestImplementation 'androidx.test.ext:junit:1.1.5'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    }
    
  • 清理并同步项目
    点击Android Studio右上角的「Sync Project with Gradle Files」同步配置,再依次执行「Build > Clean Project」和「Build > Rebuild Project」完成构建。

完成以上操作后,警告即可消除。若仍有问题,检查第三方依赖是否适配最新SDK版本,同步更新即可。

内容的提问来源于stack exchange,提问作者stefan sanders

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:32:43