Android 老项目运行的一般思路

一、依赖管理与更新

老项目一般只有:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值