Flutter旧项目编译APK报错android:attr/lStar未找到,需适配API33
Flutter应用升级API 33后编译报错:android:attr/lStar未找到(tflite相关问题)
处理因API版本过时被Play商店下架的旧Flutter应用,需升级至最低API级别33,编译APK时遇到:tflite:verifyReleaseResources任务报错,提示android:attr/lStar资源未找到,同时收到tflite插件废弃API警告。已尝试flutter clean、重新构建、检查依赖版本等操作,问题仍未解决,部分依赖因约束无法更新。
核心错误信息
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':tflite:verifyReleaseResources'. > A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action > Android resource linking failed ERROR:/Users/nico/Development/novo aqua/aquahelp/build/tflite/intermediates/merged_res/release/values/values.xml:194: AAPT: error: resource android:attr/lStar not found. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. BUILD FAILED in 22s Running Gradle task 'assembleRelease'... 22.8s Gradle task assembleRelease failed with exit code 1
tflite插件废弃API警告
Note: /Users/nico/.pub-cache/hosted/pub.dev/tflite-1.1.2/android/src/main/java/sq/flutter/tflite/TflitePlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/nico/.pub-cache/hosted/pub.dev/tflite-1.1.2/android/src/main/java/sq/flutter/tflite/TflitePlugin.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
当前项目配置
android/app/build.gradle
buildscript { ext.kotlin_version = '1.8.22' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.6.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } } plugins { id "com.android.application" id "kotlin-android" // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id "dev.flutter.flutter-gradle-plugin" } def localProperties = new Properties() def localPropertiesFile = rootProject.file("local.properties") if (localPropertiesFile.exists()) { localPropertiesFile.withReader("UTF-8") { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty("flutter.versionCode") if (flutterVersionCode == null) { flutterVersionCode = "1" } def flutterVersionName = localProperties.getProperty("flutter.versionName") if (flutterVersionName == null) { flutterVersionName = "1.0" } android { namespace = "com.example.aquahelp" compileSdk = 33 ndkVersion = flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 allWarningsAsErrors false lintOptions { disable 'Deprecation' disable 'Unsafe' } } defaultConfig { applicationId = "com.example.aquahelp" minSdk = 26 targetSdk = 33 versionCode = flutterVersionCode.toInteger() versionName = flutterVersionName } buildTypes { release { signingConfig = signingConfigs.debug } } } dependencies { implementation "androidx.appcompat:appcompat:1.4.0" // Atualize para androidx implementation "androidx.core:core-ktx:1.7.0" // Atualize para androidx implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.22" // Certifique-se de que a versão do Kotlin seja compatível } flutter { source = "../.." } tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked" }
android/build.gradle
buildscript { ext.kotlin_version = '1.8.22' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.6.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } }
pubspec.yaml
name: aquahelp description: A new Flutter project. version: 1.0.0 environment: sdk: '>=3.2.6 <4.0.0' dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter intl: ^0.19.0 percent_indicator: ^4.2.3 image_picker: ^1.1.2 url_launcher: ^6.3.0 cupertino_icons: ^1.0.2 flutter_plugin_android_lifecycle: ^2.0.21 tflite_flutter: ^0.9.0 tflite_flutter_helper: ^0.3.0 dev_dependencies: flutter_test: sdk: flutter #flutter_launcher_icons: "^0.13.1" flutter_icons: android: "launcher_icon" ios: true image_path: "icons/icon.png" flutter: uses-material-design: true assets: - assets/labels.txt - assets/labels2.txt - assets/model_unquant.tflite
已尝试的解决方法
- 执行
flutter clean和flutter build apk - 检查依赖版本并尝试更新
- 核对build.gradle配置,确保Kotlin与Gradle插件版本兼容
解决方案建议
1. 排除过时的tflite依赖
错误中出现的tflite:1.1.2是废弃包,而你已使用官方维护的tflite_flutter,需强制排除旧包:
在android/app/build.gradle的android块中添加:
android { // 原有配置 configurations.all { exclude group: 'sq.flutter', module: 'tflite' } }
2. 更新AndroidX依赖至API 33兼容版本
android:attr/lStar需要AndroidX Core 1.8.0+支持,修改android/app/build.gradle的依赖块:
dependencies { implementation "androidx.appcompat:appcompat:1.6.1" implementation "androidx.core:core-ktx:1.10.1" implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.22" }
3. 升级compileSdk到34(可选但推荐)
Play商店要求最低API 33,升级compileSdk到34可提升兼容性:
android { compileSdk = 34 targetSdk = 34 // 原有配置 }
4. 彻底清理缓存并重新构建
执行以下命令清除旧缓存:
flutter clean rm -rf ~/.pub-cache/hosted/pub.dev/tflite-1.1.2 flutter pub get flutter build apk --release
内容的提问来源于stack exchange,提问作者NicoNicotina
相关产品推荐
相关产品推荐

