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

Flutter构建Release APK失败:Android资源链接错误求助

Solution for Android Resource Linking Errors in Flutter Release APK Build

Hey there, let's break down how to fix this frustrating resource linking issue you're facing. The errors about missing android:attr/fontVariationSettings and android:attr/ttcIndex usually stem from outdated dependencies, mismatched Android SDK versions, or unmaintained third-party plugins. Here are actionable steps to resolve this:

1. Align and Upgrade Android SDK & Gradle Versions

First, make sure your project's Android configuration uses consistent, up-to-date versions. Outdated compileSdkVersion or targetSdkVersion often clash with modern dependency libraries:

  • Open android/app/build.gradle and update these values to a recent API level (33 is a safe, widely supported choice right now):
    android {
        compileSdkVersion 33
        defaultConfig {
            targetSdkVersion 33
            // ... other existing configs
        }
    }
    
  • Update your Gradle tooling to match:
    • In android/build.gradle, set the Android Gradle plugin version to one compatible with your SDK version (e.g., 7.4.2 for SDK 33):
      buildscript {
          dependencies {
              classpath 'com.android.tools.build:gradle:7.4.2'
              // ... other classpath entries
          }
      }
      
    • In android/gradle/wrapper/gradle-wrapper.properties, use a matching Gradle distribution:
      distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
      

2. Force Updated AndroidX Core Library

The error points to an outdated core-1.0.1 dependency, which lacks the required attributes. Force your project to use a newer, compatible version of the AndroidX core library:
Add this block to android/build.gradle inside the allprojects section:

allprojects {
    repositories {
        // ... your existing repositories
    }
    configurations.all {
        resolutionStrategy {
            force 'androidx.core:core:1.7.0' // Or a newer stable version available
        }
    }
}

This overrides the old core library version pulled in by problematic plugins like flutter_appavailability.

3. Fix or Replace the Troublesome Plugin

Your error originates from the flutter_appavailability plugin, which seems to be unmaintained (relying on outdated Android dependencies). Try these options:

  • Update the plugin: Check pub.dev for the latest version of flutter_appavailability — if an update exists, upgrade it in your pubspec.yaml.
  • Replace the plugin: If no update is available, switch to a maintained alternative (e.g., package_info_plus for basic app info, or other app availability plugins that support AndroidX).
  • Override plugin's Android settings: As a last resort, add an override to allow the plugin to use your project's AndroidX settings. In android/app/build.gradle under defaultConfig, add:
    defaultConfig {
        // ... existing config
        multiDexEnabled true
        manifestPlaceholders = [
            'flutterAppAvailabilityOverride': 'com.example.flutter_appavailability'
        ]
    }
    

4. Clean Caches and Rebuild

Old cached files often cause unexpected conflicts. Run these commands to start fresh:

flutter clean
rm -rf ~/.gradle/caches/ # For macOS/Linux; delete .gradle/caches folder manually on Windows
flutter pub get
flutter build apk --release

Why Setting compileSdkVersion to 28 Didn't Work

Even though API 28 supports the missing attributes, the problem was that the outdated core-1.0.1 library (pulled in by flutter_appavailability) didn't include those attributes. Force-upgrading the core library ensures your project uses a version that has them, regardless of what the plugin specifies.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 20:42:36