Flutter App stuck at "Running Gradle task 'assembleDebug'... "

GradleFlutterYamlFlutter Dependencies

Gradle Problem Overview


When I run the app it get stuck

Launching lib\main.dart on Lenovo A319 in debug mode...
Running Gradle task 'assembleDebug'...
(This is taking an unexpectedly long time.)

It never initialize Gradle nor the dependencies

Gradle Solutions


Solution 1 - Gradle

Here is solution in my case.

  1. Open your flutter Project directory.
  2. Change directory to android directory in your flutter project directory cd android
  3. clean gradle ./gradlew clean
  4. Build gradle ./gradlew build or you can combine both commands with just ./gradlew clean build (Thanks @daniel for the tip)
  5. Now run your flutter project. If you use vscode, press F5. First time gradle running assembleDebug will take time.

PS: Delete gradle in case of all that steps don't work

Solution 2 - Gradle

flutter run -v showed that I was stuck on

Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip

This was going to take hours, as for some reason the download speed was ~10kB/s on a decent DSL connection.

Solution:

  1. Interrupt gradle build
  2. Download the required gradle zip from a fast mirror. e.g. https://distfiles.macports.org/gradle/gradle-5.6.2-all.zip
  3. Copy gradle-5.6.2-all.zip to C:\Users\ <MyUsername>\.gradle\wrapper\dists\gradle-5.6.2-all\9st6wgf78h16so49nn74lgtbb (of course the last folder will have a different name on your PC)
  4. flutter run and voilà.

Solution 3 - Gradle

In my case, Windows Firewall was causing this problem. After I disabled it temporarily the problem was gone. Worth giving it a try. Good luck!

Solution 4 - Gradle

If you are on Windows: try adding firewall exceptions to your Android Studio.

  1. Go to:
    > Control Panel\System and Security\Windows Defender Firewall\Allowed apps
  2. Hit the button: > Allow another app
  3. Add your new firewall exceptions: > studio.exe and studio64.exe

I hope this can be useful for you too.

Solution 5 - Gradle

If Running Gradle task assembledebug is taking unexpectedly long time, try updating Gradle in your project. (Downloading latest zip file)

You can follow steps in this answer.

Or try by:

  1. Open a project in Android Studio
  2. Right-click on android in Projects Panel
  3. Go down to Flutter and click on the 'Open Android module in Android Studio'.

(See screenshot for reference)

Steps 1 to 3

This should open the project as an Android Project.

  1. Now, click on 'gradle' in the right panel.
  2. Next, click on 'Execute Gradle Task' icon

Steps 4 and 5

This should open a 'Run Anything' window.

  1. Now, Run the command gradlew clean
  2. and, then run gradlew build
  3. If prompted by Android Studio to 'Update Gradle Plugin', do that.

Update Gradle Plugin

The update would download the required .zip files. And, your apps should work fine after that.

Solution 6 - Gradle

I am using VS Code on Ubuntu 18.04

For me it was a background download of the appropriate android sdk build tools for my connected device. Running flutter run -v showed that it was downloading android SDK build tools which usually take some time. Once it was done, the flutter app compiled and ran successfully.

Solution

  1. Ensure you have installed android sdk tools and added them to the environment path. I assume you have downloaded android sdk tools.

  2. Ensure you have installed gradle and added it to the path

  3. Ensure you have installed latest dart and flutter sdks

For no 1 and 2 please refer to this post:

Setting up flutter without Android studio

Solution 7 - Gradle

There were two reasons for me on Archlinux:

  1. I needed to unset TERM which was set to xterm-256color (reference).
  2. For some reason, flutter stable was not working for me; so I switched to master with: flutter channel master && flutter upgrade. I'll be able to switch back to flutter stable when the fix in master makes its way into stable (reference).

Solution 8 - Gradle

For me what worked was clean wipe the emulator data by AVD Manager

Wipe data by AVD Manager

Solution 9 - Gradle

This worked for me.I got an issue with license acceptance. First you need to go through the flutter directory and then run the command

C:\Users\thrishool\flutterProjects\flutter>flutter doctor

Then it will display if everything is fine or not.I got an issue that, I didnot accept all the licenses.So you need to accept them all.Now type this in cmd

C:\Users\thrishool\flutterProjects\flutter>flutter doctor --android-licenses

Accept all the licenses and you are good to go.

Solution 10 - Gradle

This problem occurred on my system because of the Zen Kernel.

I installed the Linux-LTS kernel and started system using this.

Then my project backed to compile again.

Solution 11 - Gradle

For me simply the process took too much time. It kept running for about 10 mins and finally the app started running.

Solution 12 - Gradle

For creating an apk for Android in Flutter this issue sometimes happens. I had the luck of facing this issue as well. Here are the few ways it can be solved:

1. Due to androidX

If you followed recommended route from here: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

Try this:

Check with steps in “not recommended” way in above tutorial if every listed files is same as in your project, especially : in root/android/gradle/wrapper/gradle-wrapper.properties set distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip in root/android/build.gradle, set dependencies { classpath 'com.android.tools.build:gradle:3.3.2' }

check if root/android/app/build.gradle SDK version is set to minimum 28 for: compileSdkVersion 28 and targetSdkVersion 28 Thank you.

Solution 13 - Gradle

In my case I forgot to download Google Web Driver. It’s running once I downloaded Google Web Driver.

Solution 14 - Gradle

In Android Studio:

Tools -> Flutter -> Flutter clean.

After that just run the app

Solution 15 - Gradle

I stumbled on this problem when I was running my app without debugging it. Theres two option

  1. Start Debugging
  2. Run without Debugging

I was doing the second option the whole time which got me stuck in that running graddle loop. I fixed my problem with the first option.

Solution 16 - Gradle

This is likely one of number of issues and some of the recommended troubleshooting can be found here.

  1. Check that you are building against an Android sdk that you have installed... in your build.gradle file check the compileSdkVersion.

  2. You can try uninstalling and reinstalling the relevant SDK.

  3. Some users have reported that they had to resintall Dart.

Without a little more information basic troubleshooting is the best we can offer sorry.

Good luck.

Solution 17 - Gradle

Had the same issue because of the wrong compileSdkVersion in the build.gradle file. Working fine now.

Solution 18 - Gradle

It is taking time on windows 10 as the Android studio needs firewall permission to connect to the device(AVD). There can be another reason that you don't have downloaded full Android SDK on your machine.
To check the issue simply run the command on your terminal/cmd/PowerShell command tool.

flutter doctorflutter doctor

check if SDK is installed or not. Try to install and accept license using the following command

flutter doctor --android-licenses

If this doesn't resolve your problem then go to android studio and Open your Android Studio,

File-> settings->System settings(left tab) ->Android SDK ,

go to SDK Tool section in that page,

untick hide obsolete packages,

select Android SDL tools(obsolete) and press apply also install other useful tools according to your convenience.

Solution 19 - Gradle

This helped: check if root/android/app/build.gradle SDK version is set to minimum 28 for: compileSdkVersion 28 and targetSdkVersion 28

Occurs with import of Firestore.

Solution 20 - Gradle

In my case the Android Gradle Plugin Version was not updated to any version at all. So i updated it by right clicking on my project folder, clicked "Open Module Settings" and updated gradle plugin version accordingly. enter image description here

Solution 21 - Gradle

I used the command "flutter clean" in my project and it returned to work perfectly, please try. Igual a imagem

flutter clean

Solution 22 - Gradle

In my case, I need to update Android SDK built-tools.

Open in Android studio Tools->SDK Manager-SDK tools. Mark Android SDK Built-Tools, press Apply, wait for the update. After updated, press Apply and try to run.

android SDK built-tools

Solution 23 - Gradle

I fixed the issue by switching off my antivirus while running my project in the terminal

To run your project in a terminal simply type --> flutter run

Solution 24 - Gradle

This worked for me:

C:\Users<user>\AndroidStudioProjects<flutter_app>\android> gradlew clean C:\Users<user>\AndroidStudioProjects<flutter_app>\android> gradlew build

Now run it, for initial build

Running Gradle task 'assembleDebug'… ”

will take 10-12 mins after that it will be good to go.

Solution 25 - Gradle

  1. Download the required gradle zip from a fast mirror: https://distfiles.macports.org/gradle/gradle-5.6.2-all.zip

  2. Copy gradle-5.6.2-all.zip to C:\Users
    .gradle\wrapper\dists\gradle-5.6.2-all\9st6wgf78h16so49nn74lgtbb

If this does not work, go to android studio's terminal then run:- flutter run.

See what SDK platform it's asking you. like SDK API 28, 29, or 30. Then goto SDK manager and install the required SDK API. Then restart android studio.

It will work perfectly fine!!

Solution 26 - Gradle

The same problem occurred on my mac in Android Studio 4.1, unfortunately, I forgot to install Java on my machine, try installing Java.

Solution 27 - Gradle

This might also be due to developers permission, if you will be using any package which requires devices permission lets say url_launcher and you haven't given permission for that it wont run. Solution for windows is that just run ms-settings:developers this in your command prompt/ powershell and enable for developers option and then it will work fine. and if that doesnt also works then just run flutter clean and flutter create . it will work.

Solution 28 - Gradle

How are you !,

After many attempts, nothing they recommended worked for me.

My problem was that I had * .dart files with many lines of code to perform SQL create and insert operations initially in SQLite, I removed those 4072 lines of operations, the file was reduced in size and I no longer had to compile a very code file long, instead, I preloaded the database into assets, and it worked flawlessly! ..

The message that the operation is taking a long time no longer appears, I hope it serves you.

Before, when long file size

After, without SQL code operations

Solution 29 - Gradle

I solved the issue by reinstalling SDK Platform on Android studio for Android API 29

Tools->SDK Manager-SDK Platform

Next go to

Android > app > build.gradle

Make sure you also change

compileSdkVersion 29

targetSdkVersion 29

Be patient, it take longer for the first launch...But, not take forever like before.

good luck

Solution 30 - Gradle

Just connect with internet then disable your windows defender/firewall. It works for me.

Solution 31 - Gradle

With my LG G6 I have the same issue. It looks like the new versions of adb added some compatibility issues with some LG phones.

Downgrading to platform-tools version 28.0.0 solved the problem.

References:

https://superuser.com/questions/1357708/android-adb-logcat-works-only-on-shell/1357929#1357929

https://github.com/flutter/flutter/issues/18889#issuecomment-421432066

Solution 32 - Gradle

Finally i fixed it. The problem is mostly due to android SDK or gradle built tool

There are different ways you can try to fix it. way 1. check whether google drivers are installed . you can find them in sdk manager of the android studio

way 2. flutter doctor -v flutter doctor --android-licenses (#this will check whether all the licenses of android are accepted)

way 3. flutter clean;flutter build apk
flutter run ( In the start it will take time for assembledeubg so kindly be patient for 7 to 10 mins)

way 4. If this also do not work flutter clean flutter run (be patient and finally after 5 to 10 min your flutter code will run on the emulator)

Hope these solutions work for you, If not reply me back.

Solution 33 - Gradle

In my case installing JDK solved the problem.

macOS Catlina v10.15.4

Solution 34 - Gradle

Have you tried that from cli ?

flutter devices

flutter run

https://flutter.dev/docs/get-started/test-drive?tab=terminal

In a mac environment, the building process finished in 140s.

Solution 35 - Gradle

do flutter clean first then copy your project folder somewhere else close your project and open same project which is copied diffrent location. thats it !!

Solution 36 - Gradle

If you already opened a project and create another new project, make sure that you update the Gradle file based on the already runnable project version. In my case, I already installed Gradle 5.6.4 on a previous project and when I create a new project, it was 5.6.2 in the Gradle wrapper file. So I updated it.

Solution 37 - Gradle

If Running Gradle task assembledebug is taking unexpectedly long time and if its not working even after checking the solutions mentioned in this article.

Just go and create new virtual device in AVD Manager. I hope this will definitely work for you.

Solution 38 - Gradle

In my case, the issue was, project_path contained "space".

Example:

~/New Folder/myProject

Check if you have this issue.

Solution 39 - Gradle

the problem is solved using following:

  1. in android studio tools--> sdk Manager --> android sdk--> sdk platforms. dowload android sdk platform 28 dowload android sdk platform 28

now re-run ur project

Solution 40 - Gradle

nothing was working for me

I do update the flutter SDK & update all the dependencies to the latest version. after that, I open the android module as a project in android studio. It downloads some files. after completion, I do clean the project using Build->clean Project & update the Gradle version.

After that, I again open the flutter project and run the app. It's working now.... :)

Solution 41 - Gradle

I fixed this with upgrading flutter version from 2.0.5 to 2.2.0.

Solution 42 - Gradle

Can run the flutter app in profile / release mode to launch the app quickly. Note: We suppose to relax the hot reload. mode details

select profile mode run

Solution 43 - Gradle

if u are using windows 10, open your project in the terminal, and write these commands:

  1. cd android
  2. gradlew clean
  3. gradlew build

then run the project.

Note: if u face a problem like no path for JAVA_HOME so set this path C:\Program Files\Android\Android Studio\jre in the environment variable. and open project structure in android studio and set the same path in JDK path.

Solution 44 - Gradle

This solution should be working for some cases:

1 - Download Google Web Driver in Android SDK.

2 - Update Dart And Flutter in IntelliJ Idea or Android Studio or VS Code plugin.

3 - Run again.

Solution 45 - Gradle

I had the same challenge, meanwhile, doing flutter clean, flutter doctor, download gradle didn't help me and my issue stayed again. Finally the bellow steps rescued me from this trap.

1)Create a new flutter project(File--> new flutter project)
2)Transfer Lib, assets, font, pubspec.yaml, pubspec.lock 
3)pub update in pubspec.yaml of new project
4) change the kotlin version to latest version like 1.5.10 in android/build.gradle path in new project.

At the end try to rebuild your project and solve the other tiny problems which maybe occur. For instance, in my project the mentioned steps help me precisely.

Solution 46 - Gradle

cd android

run this cmd : ./gradlew clean and this ./gradlew build

Solution 47 - Gradle

taskkill /F /IM dart.exe then flutter clean

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlearnerView Question on Stackoverflow
Solution 1 - GradlekoderstoryView Answer on Stackoverflow
Solution 2 - GradleSébastienView Answer on Stackoverflow
Solution 3 - GradleGergö Marton-SzücsView Answer on Stackoverflow
Solution 4 - GradleenriqueneryView Answer on Stackoverflow
Solution 5 - GradleAditya ThakurView Answer on Stackoverflow
Solution 6 - Gradlebriancollins081View Answer on Stackoverflow
Solution 7 - GradlePaul ParkerView Answer on Stackoverflow
Solution 8 - GradleJoão Paulo S. AraujoView Answer on Stackoverflow
Solution 9 - GradleThrishool MSMView Answer on Stackoverflow
Solution 10 - Gradlebtd1337View Answer on Stackoverflow
Solution 11 - GradleUpulie HanView Answer on Stackoverflow
Solution 12 - Gradlejibril90View Answer on Stackoverflow
Solution 13 - GradleJustCodeNinjaView Answer on Stackoverflow
Solution 14 - GradleAlex ReyeView Answer on Stackoverflow
Solution 15 - GradleyungView Answer on Stackoverflow
Solution 16 - GradleDuncan PullenView Answer on Stackoverflow
Solution 17 - GradleAlexView Answer on Stackoverflow
Solution 18 - GradleUday ChauhanView Answer on Stackoverflow
Solution 19 - GradleChristian DresslerView Answer on Stackoverflow
Solution 20 - GradleRishabhView Answer on Stackoverflow
Solution 21 - GradleOsvaldo VbView Answer on Stackoverflow
Solution 22 - GradleOleksii KhoroshunView Answer on Stackoverflow
Solution 23 - GradleDayo JaiyeView Answer on Stackoverflow
Solution 24 - GradleDARK_C0D3RView Answer on Stackoverflow
Solution 25 - Gradlenuredin aliView Answer on Stackoverflow
Solution 26 - GradleEyayu TeferaView Answer on Stackoverflow
Solution 27 - GradleMithsonView Answer on Stackoverflow
Solution 28 - Gradleadal2404View Answer on Stackoverflow
Solution 29 - GradleMuhammad Zacky AsyariView Answer on Stackoverflow
Solution 30 - GradleBauroziqView Answer on Stackoverflow
Solution 31 - GradleAndré Luiz MüllerView Answer on Stackoverflow
Solution 32 - GradleUtkarsh guptaView Answer on Stackoverflow
Solution 33 - GradleMamad FarrahiView Answer on Stackoverflow
Solution 34 - Gradlegrape100View Answer on Stackoverflow
Solution 35 - GradleChetan DongarsaneView Answer on Stackoverflow
Solution 36 - GradleHaileappView Answer on Stackoverflow
Solution 37 - GradleJustinView Answer on Stackoverflow
Solution 38 - GradleAshiqur Rahman NayeemView Answer on Stackoverflow
Solution 39 - GradleYash ZadeView Answer on Stackoverflow
Solution 40 - GradlePriyankaView Answer on Stackoverflow
Solution 41 - GradlebounxyeView Answer on Stackoverflow
Solution 42 - GradleSenthilVelan ShanmugamView Answer on Stackoverflow
Solution 43 - GradleAmina BekirView Answer on Stackoverflow
Solution 44 - GradleVirothView Answer on Stackoverflow
Solution 45 - GradleJamal AzizbeigiView Answer on Stackoverflow
Solution 46 - Gradleyassine menssiView Answer on Stackoverflow
Solution 47 - GradleMt KhalifaView Answer on Stackoverflow