flutterandroid-studiobuild

Could not create task ... this and base files have different roots


I've built an app with Android Studio and Flutter and wanted to generate a signed APK. When I go to Tools->Flutter->Open Android module in Android Studio, it starts to build the project.

But after some time I get this Error and I don't know how to change the roots or what to do. It seems like the problem are just two packages (url_launcher and shared preferences)

My Project is on my hard disk F: and the flutter folder is on my hard disk C:

Error Message "Could not create task..."

Is this maybe because my project is on F: and the flutter folder with the packages in C: ? How can I change the flutter folder to F: ?


Solution

  • As mentioned by many above it is due to Pub cache directory and project directory not being on the same drive, which is a known issue

    Apart from moving both directories to the same drive there is a simple workaround of creating a symbolic junction/link for your project directory

    Assuming you have Pub cache in C drive and your project in D drive:

    1. Create a hard symbolic link in C drive to your app directory using windows command prompt:
    mklink /J C:\Development\your\project\directory\link D:\your\project\directory\real\path
    
    1. Open the project in your IDEs from symbolic junction/link
    C:\Development\your\project\directory\link instead of D:\your\project\directory\real\path
    
    1. With this everything should work as expected, however if you open terminal in IntelliJ it might give you the real path instead of symbolic link, hence after opening terminal do
    cd C:\Development\your\project\directory\link
    
    1. If you are using any custom or forked local dependencies from a relative path not absolute path and these are also in D(or any other non Pub cache) drive then you will need to create symbolic links for these paths as well e.g.:
    mklink /J C:\Development\Flutter\custom_dependencies D:\Development\Flutter\custom_dependencies
    

    If you use PoweShell then you need to use New-Item to create symbolic directory junction:

    New-Item -ItemType Junction -Path "Link" -Target "Target"