感觉每年都要维护一下 Google Play 应用商店里的 Android App 目标 API 级别。这不,最近又收到了 Google Play Console 的更新提醒:
不更新 目标 API 级别,Android 16 的用户就不能下载 App。之前 2023 年处理过一次,参考:
目标 API 级别是多少
恰好看到一篇 React Native 0.81 新版本的发布文章,里面也提到将支持 Android 16(API 级别 36)。
看来就是 36 了。
Android Studio 版本
Android Studio Narwhal | 2025.1.1 Patch 1
Build #AI-251.25410.109.2511.13752376, built on July 9, 2025
Runtime version: 21.0.6+-13391695-b895.109 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Tips
最好修改时,使用记事本修改下面的配置文件,或者 VSCode 修改。
如果直接打开 Android Studio 修改,这些历史项目会先拉取一堆没有用的依赖,浪费时间。不如一次性通过记事本修改完后,再打开 Android Studio。
Could not install Gradle distribution
Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-8.0-bin.zip'. Reason: java.net.SocketTimeoutException: Read timed out
参考:
替换 gradle\wrapper\gradle-wrapper.properties 中的 gradle 下载链接为国内腾讯云的链接:
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip # 注释掉
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.13-bin.zip
注意,需要同时升级 gradle 的版本,否则会报错:
Your build is currently configured to use incompatible Java 21.0.6 and Gradle 8.0. Cannot sync the project.
We recommend upgrading to Gradle version 9.0-milestone-1.
The minimum compatible Gradle version is 8.5.
The maximum compatible Gradle JVM version is 19.
Possible solutions:
- Upgrade to Gradle 9.0-milestone-1 and re-sync
- Upgrade to Gradle 8.5 and re-sync
com.android.application version 问题
Build file 'build.gradle' line: 10
Plugin [id: 'com.android.application', version: '8.0.1', apply: false] was not found in any of the following sources:
解决方法参考:
Android Studio 2025 新版本踩大坑, Plugin com.android.application was not found
修改配置
更新项目的 build.gradle 文件。在项目的 build.gradle 文件中,找到 targetSdkVersion 属性并将其设置为要升级到的目标 API 级别。例如,要将目标 API 级别升级到 33,您需要将 targetSdkVersion 设置为 33。
需求修改的地方:
compileSdk 36
targetSdk 36
不要忘了修改 versionCode 和 versionName
Android resource linking failed
在本机测试时,编译报错:
aapt2.exe E 08-16 20:09:34 5448 11028 LoadedArsc.cpp:94] RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data.
aapt2.exe E 08-16 20:09:34 5448 11028 ApkAssets.cpp:152] Failed to load resources table in APK 'D:\android_sdk\platforms\android-36\android.jar'.
error: failed to load include path D:\android_sdk\platforms\android-36\android.jar.
https://github.com/flutter/flutter/issues/153893
Also re the error this issue is about, if you need immediate unblocking you can either bump your AGP version to 8.1.0 or higher (in the plugins block of
点击右下角的 Android Studio AGP 升级提示,会自动修改 build.gradle 中的版本:
id 'com.android.application' version '8.11.1' apply false
id 'com.android.library' version '8.11.1' apply false
注意,使用国内源 新版本 Android Studio settings.gradle 中切换国内源
Unknown Kotlin JVM target: 21
解决这个问题,参考:
Unknown Kotlin JVM target: 21, Android Studio 2025
升级 kotlin 版本
一个好多年不升级的项目,报错:
Cannot use @TaskAction annotation on method AbstractKotlinCompile.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
在 build.gradle 中将 kotlin 版本升级到 1.9.0
ext.kotlin_version = "1.9.0"
关于作者 🌱
我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式