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

Flutter模拟器运行正常但构建APK报错:android:attr/lStar未找到

解决Flutter构建APK时android:attr/lStar not found错误

方案1:强制统一所有子模块的编译SDK版本

在项目根目录的android/build.gradle中添加配置,强制所有依赖模块使用与主项目一致的compileSdkVersion和targetSdkVersion,避免子模块因版本过低无法识别lStar属性:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            android {
                compileSdkVersion 33
                defaultConfig {
                    targetSdkVersion 33
                }
            }
        }
    }
}

方案2:升级flutter_pdfview至最新兼容版本

修改pubspec.yaml依赖为当前最新稳定版(如1.3.2):

dependencies:
  flutter_pdfview: ^1.3.2

执行以下命令更新依赖并清理缓存:

flutter clean
flutter pub get

方案3:匹配Android Gradle插件与Gradle版本

在android/build.gradle的buildscript块中,确保插件版本与compileSdkVersion 33兼容:

buildscript {
    ext.kotlin_version = '1.8.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

同时在gradle/wrapper/gradle-wrapper.properties中使用匹配的Gradle版本:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

方案4:彻底清理缓存后重建项目

执行以下命令清除所有缓存文件,再重新构建:

flutter clean
rm -rf android/.gradle android/build
rm -rf .dart_tool build
flutter pub get
flutter build apk --release

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 02:43:21