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

11

15

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: ?

Ploughman answered 21/10, 2021 at 13:52 Comment(1)
I'm also having this issue, did you managed to solve it?Powdery
K
3

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"
Kalinin answered 24/12, 2023 at 14:57 Comment(0)
M
38

As a workaround, you can do the following steps -

  1. run flutter clean
  2. do the Gradle sync without flutter pub get and make necessary changes to native android code.
  3. do pub get and run the app.
Merrick answered 25/8, 2022 at 13:34 Comment(4)
this answer saved me a million times, which I could do multiple upvotesCostumier
Saved a my precious time.Marismarisa
This should be accepted answerOfay
whats the command for 2.? Gradle sync not existsCommodity
P
21

I fixed mine by moving the project directory to the same drive. My project was stored in E:\ so, I moved it to C:.

My answer is almost the same as rvr93's answer but I did not add anything to the environment variables.

Parasite answered 4/4, 2022 at 9:24 Comment(1)
I created an issue which you can upvote: github.com/flutter/flutter/issues/105395Stunk
S
10

Create a directory in the same drive as your project and add PUB_CACHE environment variable. Run flutter pub get.

This worked for me.

Selfaddressed answered 1/1, 2022 at 18:35 Comment(3)
I created an issue which you can upvote: github.com/flutter/flutter/issues/105395Stunk
This is the only solution working for me, because my flutter project is a dependency in a native project.Hysterics
This worked for me for my Flutter module added to native android app as add2app.Waltman
L
5

As a workaround, you can do the following steps :

    1. Open a terminal.
    1. Run flutter clean.
    1. Do the Gradle sync without flutter pub get and make necessary changes to native Android code or click on try again.
    1. Do flutter pub get and run the app.
    1. You will see that the SHA1 has been generated.
Lashaun answered 17/12, 2022 at 18:16 Comment(0)
P
3

I had your same issue, Gradle couldn't sync the android module, I solved it by deleting the android/ directory from the Flutter project, then recreate it using the command flutter create --platforms android .

Notice the "." at the end of the command it's part of it, it means create the Android project in the current directory.

Powdery answered 12/12, 2021 at 8:47 Comment(2)
Thanks that's good to know :) I just had a work around and copied the whole project to the C: hard disk. Then it worked :)Ploughman
I created an issue which you can upvote: github.com/flutter/flutter/issues/105395Stunk
D
3

I have the same issue, it seems the flutter project and the SDKs are in different prtitions of the hard disk

just go to the project root and run flutter clean then go to the android folder and delete the .gradle folder then back to the project root and run flutter pub get

and rebuild the app

Declass answered 25/11, 2022 at 19:54 Comment(0)
K
3

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"
Kalinin answered 24/12, 2023 at 14:57 Comment(0)
M
1

I faced the same issue in my android project after upgrading gradle.

My project was in my D drive, and I had set the destination folder for the generated apk in my desktop, which is in C drive. I changed the destination folder to a folder in D drive, and the issue got resolved.

Mika answered 30/4, 2022 at 5:59 Comment(0)
R
1

I was facing the same issue all I did was to go build.gradle file in android folder and then change the following code as follows

    dependencies {
//CHANGE THE Version in  YOUR BUILD.GRADLE FILE
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

This is a temporary solution - track status here

Riverside answered 3/9, 2022 at 17:56 Comment(0)
S
0

For those whose Gradle Sync failed, follow these steps:

  1. Do flutter clean in your project terminal.
  2. Open android folder of your project using Android Studio - Android Studio->File->Open->Your_Project->Android.
  3. Now do Gradle Sync.
  4. Close your android project.
  5. Do flutter pub get in your flutter project terminal now.
Sandglass answered 22/12, 2023 at 13:37 Comment(0)
M
0

If the project is not on the C drive, create a folder named Pub under the same drive letter as the project for plug-in caching, and then configure the folder path to the system environment variable PUB_CACHE, otherwise an error will be reported when compiling the Android native project.

Metrology answered 15/1 at 12:44 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Helaina

© 2022 - 2024 — McMap. All rights reserved.