Category: Flutter

Embark on a journey to learn and master Flutter, the versatile framework for building natively compiled applications for mobile, web, and desktop. From the basics of Dart programming to creating beautiful and responsive user interfaces, follow along as I explore and share practical insights, challenges, and solutions. I hope this content serves as a helpful guide for beginners like me and anyone interested in creating powerful applications with Flutter.

  • 💥 Fixing Kotlin Daemon Errors During Flutter AAB Build

    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.