Android Studio and Flutter: "this and base files have different roots"
If Android Studio throws “this and base files have different roots” when you build a Flutter project, the cause is almost always that your Flutter Pub cache lives on a different drive than your source code. On Windows, parts of the Dart/Flutter toolchain compute a relative path between your project and the packages in the Pub cache, and that calculation fails when the two are on separate drives — for example, project on E: and the cache on C:. The fix is to move the Pub cache onto the same drive as your code and point Flutter at the new location with the PUB_CACHE environment variable.
Move the Pub cache
By default the cache lives at:
1
C:\Users\<YOURNAME>\AppData\Local\Pub\Cache
Move that whole folder to the drive your source is on, for example:
1
E:\src\Pub\Cache
Point Flutter at the new location
Create a new environment variable named PUB_CACHE set to the new path (e.g. E:\src\Pub\Cache). Set it as a user or system environment variable so it persists across reboots, then restart Android Studio and any open terminals so the new value is picked up.
Repair the cache
After moving the folder, ask Flutter to re-download and verify everything so all packages are consistent in the new location:
1
flutter pub cache repair
Then run a clean build:
1
2
flutter clean
flutter pub get
Why this happens (and how to avoid it)
Windows cannot express a relative path between two different drive letters, yet parts of the toolchain assume a relative path can always be built between your project and its dependencies. Keeping the project and the Pub cache on the same drive sidesteps the problem entirely. If you would rather not move the cache, the alternative is simply to keep your Flutter projects on the same drive the cache already uses.