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

如何解决Flutter Android资源链接失败(TextAppearance缺失)错误?

问题描述

更新Android Studio、Flutter和Gradle后,构建时持续出现以下错误:

Execution failed for task ':app:processDebugResources'.

A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction

Android resource linking failed
error: resource style/TextAppearance.Compat.Notification.Info (aka (appID):style/TextAppearance.Compat.Notification.Info) not found.
error: resource style/TextAppearance.Compat.Notification.Info (aka (appID):style/TextAppearance.Compat.Notification.Info) not found.
error: resource style/TextAppearance.Compat.Notification.Info (aka (appID):style/TextAppearance.Compat.Notification.Info) not found.
error: resource style/TextAppearance.Compat.Notification (aka (appID):style/TextAppearance.Compat.Notification) not found.
error: resource style/TextAppearance.Compat.Notification (aka (appID):style/TextAppearance.Compat.Notification) not found.
error: resource style/TextAppearance.Compat.Notification (aka (appID):style/TextAppearance.Compat.Notification) not found.
error: resource style/TextAppearance.Compat.Notification.Time (aka (appID):style/TextAppearance.Compat.Notification.Time) not found.
error: resource style/TextAppearance.Compat.Notification.Time (aka (appID):style/TextAppearance.Compat.Notification.Time) not found.
error: resource style/TextAppearance.Compat.Notification.Time (aka (appID):style/TextAppearance.Compat.Notification.Time) not found.
error: resource style/TextAppearance.Compat.Notification.Title (aka (appID):style/TextAppearance.Compat.Notification.Title) not found.
error: resource style/TextAppearance.Compat.Notification.Title (aka (appID):style/TextAppearance.Compat.Notification.Title) not found.
error: resource style/TextAppearance.Compat.Notification.Title (aka (appID):style/TextAppearance.Compat.Notification.Title) not found.
error: failed linking references.

项目配置

app/build.gradle

def localProperties = new Properties()    
def localPropertiesFile = rootProject.file('local.properties')    
if (localPropertiesFile.exists()) {
      localPropertiesFile.withReader('UTF-8') { reader ->
            localProperties.load(reader)        
    }    
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
flutterVersionCode = '24'

def flutterVersionName = localProperties.getProperty('flutter.versionName')
flutterVersionName = '1.0.25'

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
    configurations {
        all*.exclude module: 'core' // This removes all other versions of `support-v4` if gets duplicated from all the artifacts.
    }
    compileSdkVersion 33

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "AppID"
        minSdkVersion 33
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
    namespace 'com.mechengjp.math'
}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:32.0.0')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.android.gms:play-services-ads:22.0.0'
    implementation 'com.google.firebase:firebase-analytics'
    implementation "com.google.firebase:firebase-messaging:23.1.2"
}

flutter doctor -v 输出

[✓] Flutter (Channel stable, 3.10.1, on macOS 13.2 22D49 darwin-arm64, locale en-JP)
    • Flutter version 3.10.1 on channel stable at /Users/sae/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3d8effc68 (3 days ago), 2023-05-16 17:59:05 -0700
    • Engine revision b4fb11214d
    • Dart version 3.0.1
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/sae/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.2 22D49 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 113.0.5672.126

[✓] Network resources
    • All expected network resources are available.

• No issues found!
解决方案

错误核心原因是全局排除了core模块,而缺失的TextAppearance.Compat.Notification相关样式属于AndroidX Core库,被误排除了。

  • 步骤1:移除错误的排除规则
    打开app/build.gradle,删除android块下的这段配置:

    configurations {
        all*.exclude module: 'core' // This removes all other versions of `support-v4` if gets duplicated from all the artifacts.
    }
    

    注释中提到的support-v4已被AndroidX替代,该规则会误删必要的AndroidX Core库。

  • 步骤2:添加AndroidX Core依赖(可选)
    若移除排除规则后仍报错,手动添加AndroidX Core依赖到dependencies块:

    implementation 'androidx.core:core-ktx:1.10.1'
    

    版本号可根据compileSdkVersion选择适配的最新稳定版。

  • 步骤3:清理并重新构建项目
    执行以下命令清理缓存并重建:

    flutter clean
    flutter pub get
    cd android
    ./gradlew clean
    cd ..
    flutter run
    

另外,当前minSdkVersion与compileSdkVersion均为33,版本一致无问题;Firebase和Ads的依赖版本也适配该SDK版本,无需调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 04:12:55