一、依赖管理与更新
老项目一般只有:
repositories {
google()
jcenter()
}
jcenter()已经弃用了,要进行替换,以及添加镜像源,防止下载超时报错:
repositories {
maven { url 'https://maven.aliyun.com/repository/public' } // 阿里云镜像
maven { url 'https://maven.aliyun.com/repository/google' }
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://jcenter.bintray.com/" } // 添加此项
}
还有一些老项目使用了老版本的
gradle-bintray-plugin,会提示报错:Could not find com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5. 要进行替换
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
// 替换为 maven-publish
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.28.0'
二、资源文件AndroidManiffest.xml
将文件中package剪切至,build.gradle文件中
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.origin.xxx">
...
</manifest>
android {
namespace "com.origin.xxx"
...
}
三、AndroidX 迁移不完整导致的问题
会提示报错:Configuration :x:debugRuntimeClasspath contains AndroidX dependencies, but the android.useAndroidX property is not enabled, which may cause runtime issues. Set android.useAndroidX=true in the gradle.properties file and retry.
所需要做的就是,强制启用 AndroidX
在项目根目录的 gradle.properties 文件中添加:
# 开启 AndroidX 支持
android.useAndroidX=true
# 自动转换第三方库的 support 包到 AndroidX
android.enableJetifier=true
四、检查模块级 build.gradle(可选,不影响运行)
确保所有模块都使用 compileSdkVersion 34 或更高
五、switch 中的 R.id 报红
已经有大佬提供文章了,引用一下 新版android studio中使用 switch-case报错找不到id
在 gradle.properties 里添加如下三行代码
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
1066

被折叠的 条评论
为什么被折叠?



