我正在开发一个较旧的 Flutter 应用程序,由于 API 级别过时,该应用程序已从 Play 商店中删除。我目前正在尝试更新并重新发布它,但在更新过程中遇到了这些问题。 我需要按照 Play 商店的要求将 Android 最低 API 级别维持在 33。
我在尝试在 Flutter 中编译 APK 时遇到问题。该错误发生在
:tflite:verifyReleaseResources
任务期间,指出无法找到 android:attr/lStar
资源。以下是完整的错误消息:
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.
我已经尝试过
running flutter clean
和 flutter build apk
但错误仍然存在。我还注意到 14 个软件包具有与当前依赖项约束不兼容的较新版本。
这是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
我尝试清理项目并重建 APK,检查依赖项版本,并检查 build.gradle 文件以确保一切设置正确。我还更新了依赖项并确保 Kotlin 版本和 Gradle 插件兼容。
我还注意到 14 个软件包具有与当前依赖关系约束不兼容的较新版本。
Resolving dependencies...
Downloading packages...
collection 1.18.0 (1.19.0 available)
ffi 2.1.2 (2.1.3 available)
flutter_plugin_android_lifecycle 2.0.21 (2.0.22 available)
http_parser 4.0.2 (4.1.0 available)
image_picker_android 0.8.12+11 (0.8.12+13 available)
leak_tracker 10.0.5 (10.0.7 available)
leak_tracker_flutter_testing 3.0.5 (3.0.8 available)
material_color_utilities 0.11.1 (0.12.0 available)
mime 1.0.5 (1.0.6 available)
quiver 3.2.1 (3.2.2 available)
string_scanner 1.2.0 (1.3.0 available)
test_api 0.7.2 (0.7.3 available)
url_launcher_android 6.3.8 (6.3.10 available)
vm_service 14.2.4 (14.2.5 available)
Got dependencies!
14 packages have newer versions incompatible with dependency constraints.
由于我仍在学习如何使用 Flutter 和 Gradle,所以我不确定如何解决这个问题。任何有关如何解决此问题并成功编译 APK 的指导或建议将不胜感激。谢谢!
在 android/build.gradle 上添加此解决方法已经为我们解决了这个问题。
subprojects {
afterEvaluate { project ->
if (project.plugins.hasPlugin("com.android.application") ||
project.plugins.hasPlugin("com.android.library")) {
project.android {
compileSdkVersion 34
buildToolsVersion "34.0.0"
}
}
}
}