Android 设置 targetSdkVersion

WARNING

请注意,当前域名 https://dev.weixin.qq.com/docs/framework 文档已不维护,请前往微信文档中心open in new window 找到对应的新文档继续使用

  • targetSdkVersion 是用于指定应用的目标Android版本(API等级),设置 targetSdkVersion 的值即表示 App 适配的 Android版本(API等级),设置低版本的 targetSdkVersion 会使 APP 兼容模式运行,也就可能无法用到新系统的特性,甚至在兼容模式下运行可能存在安全漏洞等问题,因此开发者需谨慎设置。

注意

1、多端应用在开发者工具中默认的 targetSdkVersion 默认值为 29,且支持可设置的最小值为 29(即开发者可设置 ≥ 29 的值;一些应用市场会要求设置较高的 targetSdkVersion 才可以提交,开发者在提交应用市场审核时按照应用市场要求设置)

2、App升级时 targetSdkVersion 只能增加不能降低,也就是说 targetSdkVersion 高的App无法被 targetSdkVersion 低的App覆盖安装

3、targetSdkVersion 值为 Number 类型,且必须为正整数,取值范围参考下方的 Android 版本列表中的 API 等级

targetSdkVersion 配置指引

  • 将开发者工具升级至最新的 nightly 版open in new window,进入到多端模式,点击 project.miniapp.json ,可参考下图进行 targetSdkVersion 配置
  • 补充:配置之后重新构建 APK 即可生效

API等级与Android版本对应列表

平台版本API 级别
Android 14open in new window34open in new window
Android 13open in new window33open in new window
Android 12open in new window32open in new window
Android 12open in new window31open in new window
Android 11open in new window30open in new window
Android 10open in new window29open in new window
Android 9open in new window28open in new window
Android 8.1open in new window27open in new window
Android 8.0open in new window26open in new window
Android 7.1.1、7.1open in new window25open in new window
Android 7.0open in new window24open in new window
Android 6.0open in new window23open in new window
Android 5.1open in new window22open in new window
Android 5.0open in new window21open in new window
Android 4.4open in new window19open in new window
Android 4.3open in new window18open in new window
Android 4.2、4.2.2open in new window17open in new window
Android 4.1、4.1.1open in new window16open in new window
Android 4.0.3、4.0.4open in new window15open in new window
Android 4.0、4.0.1、4.0.2open in new window14open in new window
Android 3.2open in new window13open in new window
Android 3.1.xopen in new window12open in new window
Android 3.0.xopen in new window11open in new window
Android 2.3.4、2.3.3open in new window10open in new window
Android 2.3.2、2.3.1、2.3open in new window9open in new window
Android 2.2.xopen in new window8open in new window
Android 2.1.xopen in new window7open in new window
Android 2.0.1open in new window6open in new window
Android 2.0open in new window5open in new window
Android 1.6open in new window4open in new window
Android 1.5open in new window3open in new window
Android 1.1open in new window2
Android 1.01