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

Flutter构建release版APK报background_location:verifyReleaseResources错如何解决

问题描述

Flutter应用调试运行、常规构建均正常,构建release或profile版本APK时出现如下报错:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':background_location:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
   > Android resource linking failed
     ERROR:C:\Users\Misha\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\background_location-0.6.1\android\src\main\AndroidManifest.xml:10:9-15:37: AAPT: error: attribute android:foregroundServiceType not found.
已尝试操作
  • 执行 flutter clean 清理项目构建缓存
  • 执行 flutter pub cache repair 修复Pub依赖缓存
  • 升级Gradle版本
  • 已开启AndroidX支持
解决方案

报错的核心原因是 android:foregroundServiceType 是Android 10(API Level 29)才新增的系统属性,background_location 0.6.1版本的Android清单文件使用了该属性,当项目的编译SDK版本低于29时就会识别不了该属性,触发资源链接错误。可通过以下两种方式解决:

  1. 升级项目编译SDK版本
    打开项目路径下的 android/app/build.gradle 文件,将 compileSdkVersion 数值修改为29或更高即可,示例配置如下:
android {
    // 只要数值≥29即可,推荐使用当前最新稳定版编译SDK
    compileSdkVersion 33
    
    defaultConfig {
        // 其余配置保持原有逻辑即可,无需修改minSdkVersion
        ...
    }
}
  1. 降级background_location插件版本
    如果你的应用不需要适配Android 10以上的前台服务类型能力,也可以将background_location插件降级到0.6.0以下版本,在 pubspec.yaml 中指定版本即可:
dependencies:
  background_location: ^0.5.0

修改完成后重新执行release构建即可恢复正常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.11 08:30:02