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为什么要把常用的,必须的那些功能默认关闭,真的恶心人。

相关推荐
程序员码歌5 小时前
【零代码AI编程实战】AI灯塔导航-总结篇
android·前端·后端
书弋江山6 小时前
flutter 跨平台编码库 protobuf 工具使用
android·flutter
任磊abc7 小时前
vscode无法检测到typescript环境解决办法
ide·vscode·typescript
来来走走9 小时前
Flutter开发 webview_flutter的基本使用
android·flutter
Jerry说前后端10 小时前
Android 组件封装实践:从解耦到架构演进
android·前端·架构
louisgeek10 小时前
Android OkHttp Interceptor
android
大王派来巡山的小旋风10 小时前
Kotlin基本用法三
android·kotlin
Jerry说前后端11 小时前
Android 移动端 UI 设计:前端常用设计原则总结
android·前端·ui
bytebeats11 小时前
Jetpack Compose 1.9: 核心新特性简介
android·android jetpack
Icey_World11 小时前
Mysql笔记-错误条件\处理程序
android