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

Flutter项目构建APK时Gradle报错:javax.xml.bind.UnmarshalException及依赖相关问题

Fixing Gradle Errors When Building Flutter APK with Firebase

Hey there, let's work through these Gradle issues you're facing while building your Flutter APK—they're typical when mixing specific Flutter SDK versions, Firebase dependencies, and Gradle configurations. Here's a step-by-step breakdown to resolve each error:

1. Resolve lintVitalRelease Dependency & lintClassPath Resolution Errors

These usually stem from lint tool conflicts or mismatched Gradle versions with your Flutter SDK.

  • Update Gradle Plugin & Wrapper:
    For Flutter 2.16.x, stick to Gradle plugin 7.0.x and Gradle wrapper 7.0.2 to ensure compatibility:

    • Open android/build.gradle, find the dependencies block under buildscript and update the classpath:
      buildscript {
          dependencies {
              classpath 'com.android.tools.build:gradle:7.0.4'
              // Keep your Firebase classpath here if present, e.g., classpath 'com.google.gms:google-services:4.3.10'
          }
      }
      
    • Open android/gradle/wrapper/gradle-wrapper.properties and set the distribution URL:
      distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
      
  • Temporarily Disable Lint Vital Checks:
    If you don't need strict release lint checks right now, add this to android/app/build.gradle inside the android block to bypass the error:

    android {
        // ... other configurations
        lintOptions {
            checkReleaseBuilds false
            disable 'InvalidPackage'
        }
    }
    

2. Fix minifyReleaseWithR8 Creation Error & XML Parse Exception

The javax.xml.bind.UnmarshalException with the French "Fin prématuré du fichier" (file ended prematurely) points to two main issues: XML configuration corruption or Java/Gradle version mismatch.

  • Check XML Configuration Files:
    Scan android/app/src/main/AndroidManifest.xml and any other XML files in your android directory for syntax errors (unclosed tags, empty files, typos). The error mentions line 1, column 1, so double-check if any XML file is empty or malformed.

  • Use Compatible Java Version:
    Flutter 2.16.x works best with Java 11. Verify your JAVA_HOME environment variable points to a Java 11 installation—avoid Java 8 or 17, as they can cause R8 compatibility issues.

  • Adjust R8/Minification Settings:
    If you don't need code shrinking right now, disable it in android/app/build.gradle under the release build type:

    buildTypes {
        release {
            signingConfig signingConfigs.debug // Replace with your production signing config later
            minifyEnabled false
            shrinkResources false
        }
    }
    

    If you need minification, ensure your proguard-rules.pro file is properly formatted and compatible with your dependencies.

3. Clean Up Firebase Dependencies

You're using both the old firebase: ^9.0.3 package and the modern split Firebase packages (firebase_core, firebase_auth, etc.). This can cause conflicts.

  • Remove firebase: ^9.0.3 from your pubspec.yaml
  • Run flutter pub get to update your dependencies

Final Steps

After making these changes:

  1. Run flutter clean to clear cached build files
  2. Rebuild with your command: flutter build apk --no-sound-null-safety

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 20:32:41