Flutter项目构建APK时Gradle报错:javax.xml.bind.UnmarshalException及依赖相关问题
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 thedependenciesblock underbuildscriptand 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.propertiesand set the distribution URL:distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
- Open
Temporarily Disable Lint Vital Checks:
If you don't need strict release lint checks right now, add this toandroid/app/build.gradleinside theandroidblock 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:
Scanandroid/app/src/main/AndroidManifest.xmland any other XML files in yourandroiddirectory 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 yourJAVA_HOMEenvironment 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 inandroid/app/build.gradleunder thereleasebuild 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.profile 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.3from yourpubspec.yaml - Run
flutter pub getto update your dependencies
Final Steps
After making these changes:
- Run
flutter cleanto clear cached build files - Rebuild with your command:
flutter build apk --no-sound-null-safety
内容的提问来源于stack exchange,提问作者Marwane Debbache

