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

Flutter打包Release版本报错::location:verifyReleaseResources执行失败

Flutter Release构建失败:Aapt2Exception 资源未找到(fontVariationSettings/ttcIndex)

FAILURE: Build failed with an exception.

  • 问题原因: 任务':location:verifyReleaseResources'执行失败。
    java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android资源链接失败
    /Users/omotayo/lasumonitor/build/location/intermediates/res/merged/release/values/values.xml:276: error: 未找到资源android:attr/fontVariationSettings。
    /Users/omotayo/lasumonitor/build/location/intermediates/res/merged/release/values/values.xml:277: error: 未找到资源android:attr/ttcIndex。
    error: 链接引用失败。
  • 建议尝试: 使用--stacktrace选项获取堆栈跟踪;使用--info或--debug选项获取更多日志输出;使用--scan选项获取完整分析信息。

问题根源分析

这两个报错的资源属性android:attr/fontVariationSettings和android:attr/ttcIndex是**Android 8.0(API等级26)**才新增的。你碰到这个问题,大概率是项目依赖的location模块(或者它的子依赖)使用的编译SDK版本低于26,和主项目的SDK版本不兼容,导致资源链接时找不到新增的属性。

一步步解决方案:

1. 升级主项目的编译SDK版本

打开Flutter项目下的android/app/build.gradle文件,把以下两个版本号调整到至少26(推荐用最新稳定版,比如34):

android {
    compileSdkVersion 34  // 最低要求26,建议选最新稳定版
    defaultConfig {
        targetSdkVersion 34  // 和compileSdkVersion保持一致或接近即可
        // 其他原有配置无需修改
    }
}

2. 强制所有依赖使用统一的SDK版本

如果修改主项目配置后仍报错,说明location依赖本身的SDK版本过低。可以在android/build.gradle中添加配置,强制所有模块使用统一的编译SDK版本:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            android {
                compileSdkVersion 34
                buildToolsVersion "34.0.0"
            }
        }
    }
}

3. 升级location相关依赖包

你使用的location插件可能是旧版本,建议去pub.dev查看对应包(比如geolocator这类常用位置插件)的最新稳定版,升级后通常会适配更高版本的Android SDK。

修改pubspec.yaml中的依赖版本:

dependencies:
  # 替换成你实际使用的location相关包
  geolocator: ^10.1.0  # 换成最新版本号

4. 清理缓存并重新构建

修改配置后务必清理旧缓存,避免残留文件干扰构建:

# 清理Flutter缓存
flutter clean

# 进入android目录清理Gradle缓存
cd android
./gradlew clean
./gradlew build --refresh-dependencies

# 返回项目根目录构建Release版本
cd ..
flutter build apk --release

如果以上步骤都无法解决问题,可以运行flutter pub deps查看location模块的依赖树,定位到具体是哪个子依赖导致的SDK版本不一致,再针对性处理。

内容的提问来源于stack exchange,提问作者Saheed Olalekan Abdulrasaq

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 05:37:41