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

Solution 1:

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:

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

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:

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:

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.