Skip to content

Fix Android Resource Linking Failed with Android-35 in Flutter Build

Problem Statement

When building a Flutter app for release (flutter build apk) with Android API level 35, you encounter the following critical error:

log
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> Android resource linking failed
   aapt2 E ... Failed to load resources table in APK .../android-35/android.jar
   error: failed to load include path .../android-35/android.jar

This issue typically occurs when:

  • Using Android Gradle Plugin (AGP) versions below 8.5 with compileSdk = 35
  • Flutter's dependencies conflict with newer Android SDKs
  • The SDK file android.jar is corrupted or incompatible

The error prevents release builds from completing, preventing app distribution despite debug builds working normally.

Solutions

Primary Solution: Update Android Gradle Plugin and Gradle

This resolves compatibility issues with SDK 35:

  1. Update Gradle version by editing android/gradle/wrapper/gradle-wrapper.properties:
properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip

TIP

Alternatively run this command in Terminal:

bash
./gradlew wrapper --gradle-version=8.9
  1. Update Android Gradle Plugin in android/settings.gradle:
groovy
pluginManagement {
    plugins {
      // ... other plugins
      id "com.android.application" version "8.5.0" apply false
    }
}
  1. Finalize Gradle Changes:
bash
flutter clean
flutter pub get

Use Flutter's Built-in SDK Versions

Instead of hardcoding SDK versions, use Flutter's predefined constants in app/build.gradle:

groovy
android {
    namespace = "com.example.flutter_application_1"
    compileSdk = flutter.compileSdkVersion // Use Flutter's variable
    ndkVersion = flutter.ndkVersion

    defaultConfig {
        minSdk = flutter.minSdkVersion // Auto-updates with Flutter
        targetSdk = flutter.targetSdkVersion
    }
}

Alternative Solution: Manual Desugering & Configuration

If AGP update isn't possible:

  1. Set default SDK in android/app/build.gradle:
groovy
android {
    compileSdkVersion 34 // Instead of 35
    targetSdkVersion 34
}
  1. Add temporary fix to gradle.properties:
properties
android.aapt2Version=8.6.1-11315950
android.suppressUnsupportedCompileSdk=35
  1. Enable desugaring for dependencies:
groovy
dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
}

Validate Common Fixes

  1. Ensure namespace in app/build.gradle matches package ID:
groovy
android {
    namespace = "com.your.package" // Must match AndroidManifest.xml
}
  1. Remove duplicate package from AndroidManifest.xml:
xml
<manifest 
    ~~package="com.your.package"~~ > <!-- Remove if already in build.gradle -->
  1. Clean project after configuration changes:
bash
flutter clean
flutter build apk --release

Best Practices for Future-Proofing

  1. Always verify Flutter's AGP compatibility
  2. Delay compileSdkVersion upgrades until Flutter officially supports newer SDKs
  3. Never hardcode SDK versions—use Flutter's variables as shown above
  4. Maintain consistent versions across:
properties
android.enableJetifier=true
android.useAndroidX=true

WARNING

API level 35 requires AGP 8.5+ to avoid resource linking issues. Using AGP <8.5 with SDK35 will consistently fail due to aapt2 incompatibilities.

Following these solutions ensures reliable Flutter release builds while maintaining Android 14+ compatibility. The primary recommendation is updating AGP to 8.5+ with Gradle 8.9 as it resolves the root cause of resource linking failures.