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

相关推荐
私房菜19 分钟前
Selinux 及在Android 的使用详解
android·selinux·sepolicy
一只特立独行的Yang1 小时前
Android中的系统级共享库
android
两个人的幸福online1 小时前
php开发者 需要 协程吗
android·开发语言·php
zhangfeng11332 小时前
2026年国际国外top10 top20流行的ai ide,
ide·人工智能
CDialog2 小时前
vscode编译ci1303sdk的源代码
ide·vscode·编辑器
修炼者2 小时前
WindowManager(WMS)构建全局悬浮窗
android
xiaoshiquan12063 小时前
Android Studio里,SDK Manager显示不全问题
android·ide·android studio
Lstone73644 小时前
Bitmap深入分析(一)
android
一起搞IT吧4 小时前
Android功耗系列专题理论之十四:Sensor功耗问题分析方法
android·c++·智能手机·性能优化