Flutter构建Release APK失败:Android资源链接错误求助
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.gradleand 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.2for 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
- In
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 yourpubspec.yaml. - Replace the plugin: If no update is available, switch to a maintained alternative (e.g.,
package_info_plusfor 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.gradleunderdefaultConfig, 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

