You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Flutter SDK至3.24后启动应用报错,求解决方案

问题解决:Flutter 3.24升级后启动报错

问题描述

昨日将Flutter SDK升级至3.24版本,今日启动应用时出现报错,尝试更新Kotlin版本并修改kotlin-stdlib-jdk7版本后问题仍未解决。

报错信息

  • AAPT: error: resource android:attr/lStar not found.
  • Your project requires a newer version of the Kotlin Gradle plugin. Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update the version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of path

当前配置

settings.gradle文件

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.2.2" apply false
    id "org.jetbrains.kotlin.android" version "1.9.25" apply false
    id "com.google.gms.google-services" version "4.3.15" apply false
}

app/build.gradle文件

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.22"
    implementation 'com.google.android.gms:play-services-location:21.1.0'
    implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.9.0"
    implementation 'com.android.support:multidex:2.0.1'
}

configurations.all {
    resolutionStrategy {
        eachDependency {
            if ((requested.group == "org.jetbrains.kotlin")
                    &&(requested.name.startsWith("kotlin-stdlib"))) {
                useVersion("2.0.10")
            }
        }
    }
}

解决方案

1. 修复Kotlin版本不兼容问题

你的配置存在Kotlin Gradle插件与stdlib版本不匹配的核心冲突:插件版本为1.9.25,但resolutionStrategy强制将stdlib替换为2.0.10,直接触发插件版本报错。

修改步骤:

  • 移除configurations.all下的resolutionStrategy代码块,取消强制修改stdlib版本的规则
  • 统一Kotlin版本,将kotlin-stdlib-jdk7和kotlin-script-runtime的版本改为与插件一致的1.9.25
  • 若要使用Kotlin 2.x版本,需同步将org.jetbrains.kotlin.android插件版本升级到2.0.10(优先保持版本一致)

修改后的app/build.gradle依赖部分:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.25"
    implementation 'com.google.android.gms:play-services-location:21.1.0'
    implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.9.25"
    implementation 'com.android.support:multidex:2.0.1'
}

2. 解决android:attr/lStar not found报错

lStar是Android 12(API 31)新增的资源属性,报错原因是项目compileSdkVersion/targetSdkVersion低于31,或依赖库引用了高版本SDK资源。

修改步骤:

  • 在app/build.gradle中,将compileSdkVersion和targetSdkVersion设置为31及以上(推荐设为34,适配Flutter 3.24要求)
  • 替换旧Support库为AndroidX(Flutter 3.24默认使用AndroidX),将com.android.support:multidex:2.0.1改为androidx.multidex:multidex:2.0.1
  • 确保第三方依赖与SDK版本兼容:play-services-location:21.1.0需要compileSdkVersion至少33,若设为34可保留该版本,也可升级至最新稳定版(如21.2.0)

示例修改后的app/build.gradle相关配置:

android {
    compileSdkVersion 34
    defaultConfig {
        targetSdkVersion 34
        // 其他原有配置...
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.25"
    implementation 'com.google.android.gms:play-services-location:21.2.0'
    implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.9.25"
    implementation 'androidx.multidex:multidex:2.0.1'
}

最后执行flutter clean,重新运行项目即可。

内容的提问来源于stack exchange,提问作者YsfKcr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 01:00:00