While preparing to publish a Flutter app to Google Play, I encountered a strange error during the flutter build appbundle
process.
Daemon compilation failed: null
java.lang.Exception ...
Caused by: java.lang.Exception: Could not close incremental caches ...
IllegalArgumentException: this and base files have different roots:
e.g., C:\path\to\pub_cache\shared_preferences_android vs D:\path\to\project
This error typically occurs when the Kotlin Incremental Compiler fails to resolve relative paths between files located on different drives (C:\ and D:\, for example).
π§© Root Cause
- Incremental cache close failure: Kotlin cache couldn’t be closed properly
- IllegalArgumentException: Relative path resolution failed due to files being on different drive roots
π How I Fixed It
β
1. Run flutter clean
In most Flutter projects, flutter clean
is the first go-to command to reset build caches:
flutter clean
flutter pub get
flutter build appbundle
β 2. Stop Gradle Daemon & Delete Caches (if needed)
If the issue persists, stop the Gradle daemon and manually delete cached data:
gradlew --stop
Recommended cache paths to delete:
C:\Users\YourUsername\.gradle
C:\Users\YourUsername\AppData\Local\Pub\Cache
β οΈ Deleting these may require re-downloading dependencies on the next build, which can take time.
β 3. Reinstall Problematic Packages
If a specific package (e.g., shared_preferences
) is causing issues, try reinstalling it:
flutter pub remove shared_preferences
flutter pub add shared_preferences
π― Result
After following the above steps, the build completed successfully and the AAB file was generated without any issues.
π Final Thoughts
Most Flutter build errors come down to corrupted caches or path conflicts. When in doubt, start with flutter clean
β it just might save you hours of debugging.