首先升级 targetSdkVersion 和 compileSdkVersion 到 35,升级后发生的报错
一、
解决方案: 升级 gradle 和 gradle 插件版本
com.android.tools.build:gradle -> 8.3.0-alpha02
gradle-wrapper.properties : distributionUrl -> gradle-8.6-bin.zip
https\://services.gradle.org/distributions/gradle-8.6-bin.zip
二、The project is using an incompatible version (AGP 8.3.0-alpha02) of the Android Gradle plugin. Latest supported version is AGP 7.3.1 See Android Studio & AGP compatibility options.
解决方案:升级as 解决报错 ,根据官网要求as升级到可兼容的AGP 版本
https://developer.android.com/studio/releases?hl=zh-cn#android_gradle_plugin_and_android_studio_compatibility
三、项目升级AGP到8.0+同步项目,遇到以下 2 个错误:
错误一: Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
解决方案:需要在app—> build.gradle 设置命名空间解决
https://developer.android.com/build/configure-app-module?hl=zh-cn#groovy
在每一个模块中,都有一个build.gradle文件和AndroidManifest.xml,现在需要做的就是把AndroidManifest.xml中package="com.aaa.bbb"包名添加到模块对应的build.gradle中。每一个模块都是这样,包括主App模块。
假设AndroidManifest.xml -> package=“com.aaa.bbb”
android {
namespace "com.aaa.bbb"
}
错误二:Cause: com/android/tools/lint/model/LintModelSeverity has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
java 类文件版本号 61.0,对应的是java 17
解决方案:升级 jdk 版本到 java 17