Reputation: 233
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: ?
Upvotes: 20
Views: 34583
Reputation: 21
Steps:
Upvotes: 2
Reputation: 1
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.
Upvotes: 0
Reputation: 404
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:
mklink /J C:\Development\your\project\directory\link D:\your\project\directory\real\path
C:\Development\your\project\directory\link instead of D:\your\project\directory\real\path
cd C:\Development\your\project\directory\link
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"
Upvotes: 7
Reputation: 1
For those whose Gradle Sync failed, follow these steps:
Upvotes: 0
Reputation: 437
As a workaround, you can do the following steps :
flutter clean
.flutter pub get
and make necessary changes to native Android code or click on try again.flutter pub get
and run the app.Upvotes: 7
Reputation: 33
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
Upvotes: 3
Reputation: 2982
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
Upvotes: 1
Reputation: 773
As a workaround, you can do the following steps -
Upvotes: 69
Reputation: 24128
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.
Upvotes: 1
Reputation: 243
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.
Upvotes: 23
Reputation: 913
Create a directory in the same drive as your project and add PUB_CACHE environment variable. Run flutter pub get
.
This worked for me.
Upvotes: 14
Reputation: 331
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.
Upvotes: 3