Android Studio Ladybug升级老项目遇到问题

背景

把一个旧小项目升级,从7.x升级到8.x遇到问题记录。

Unknown Kotlin JVM

这是错误特征:

sh 复制代码
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugKotlin'.
> Unknown Kotlin JVM target: 21

当升级的时候:

sh 复制代码
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
com.android.tools.build:gradle:8.7.1

很容易遇到这个问题,也就是第一个问题,项目无法初始化。

需要在app:build.gradle中配置:

sh 复制代码
android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}

同步项目即可解决。当然你的settings中需要配置jdk17。

BuildConfig找不到,R文件找不到

编译代码时候会发现BuildConfig,和R都是红色,不存在。

需要增加配置buildConfig。

如果你的项目需要viewBinding,就需要一样设置。

如果你项目刚好用上了aidl,对应的Java文件也无法自动生成,需要主动激活。

sh 复制代码
android {
    buildFeatures {
        viewBinding true
        buildConfig true
        aidl true
    }
}

namespace

这个错误提示很明显的,as在错误信息中告诉你如何修复。

sh 复制代码
android {
    namespace "pkg"
}

最后

as为什么要把常用的,必须的那些功能默认关闭,真的恶心人。

相关推荐
天空之城--1 小时前
Android Koin 完全指南:从原理到实践
android
zhangphil2 小时前
Android main thread主线程Choreographer doFrame发生FullSuspendCheck
android
TimeFine6 小时前
智能眼镜开发:获取真实的音频路由
android
pengyu6 小时前
【Kotlin 协程修仙录 · 渡劫境 · 中阶】 | 造化神兵:自定义 CoroutineDispatcher 与调度器的终极定制
android·kotlin
pengyu6 小时前
【Kotlin 协程修仙录 · 渡劫境 · 初阶】 | 飞升雷劫:CPS 变换与挂起函数字节码终极透视
android·kotlin
TimeFine6 小时前
智能眼镜开发:眼镜Touch后收音与触发播放系统音乐的矛盾处理
android
TimeFine7 小时前
智能眼镜开发:眼镜侧收集音频
android
又见情义7 小时前
Android 系统设置从平板版迁移至TV版实践
android
OsDepK8 小时前
xcode应用构建至testflight测试流程
ide·macos·xcode
frjc9 小时前
如何在 IDEA 中打开并运行已有Java项目
java·ide·intellij-idea