215

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

mustaccio
  • 18,234
  • 16
  • 48
  • 57
learner
  • 2,191
  • 2
  • 6
  • 10
  • 8
    `(This is taking an unexpectedly long time.)` does it mean after that time it gives back a certain result? if yes, what's the result? – Gratien Asimbahwe Dec 29 '19 at 02:46
  • 3
    is this the first time ? or was it working before ? – Henok Dec 29 '19 at 04:50
  • 4
    Are you connected to the internet? If so, please check your internet connection--assuming dependencies are not yet cached locally on your machine. Also can you please try sharing the logs after running `flutter run -v`. Lastly, you can try stopping an existing gradle daemon via `cd android && ./gradlew --stop` then run the `flutter run -v` again. – Joshua de Guzman Dec 29 '19 at 05:12
  • Hi, after waiting nearly waiting 10 mins [Log](https://pastebin.com/A4hUt9rb) the app doesn't show what it suppose to show – learner Dec 29 '19 at 15:02
  • 2
    The information you provided is not enough to know the cause you of the delay. You should provide the output of `flutter doctor`, this will narrow the bug search area. Does it do that will a specific app or all your apps? – Loïc Fonkam Dec 29 '19 at 08:30
  • @LoïcFonkam everything is fine with flutter doctor, my app is also stuck with the same error, up to 20+ minutes, then it run successfully if do want to know why does this happen – Azhar Ali May 08 '21 at 10:39

53 Answers53

221

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

Aldy
  • 2,743
  • 2
  • 12
  • 17
  • 6
    Not sure if it will work, but deleting a folder with over 80.000 files feels incredibly pleasant. Definitely ~/.gradle went out of hand – JesusIniesta Jun 17 '20 at 13:09
  • Hi. I edited the order of deleting gradle from main flow. Because most of the case solved by following step 2-6. Step 1 (deleting gradle) is optional in case of step 2 -6 not worked. – Aldy Jun 17 '20 at 14:26
  • it seems running but i have code error in my project – kreamik Oct 07 '20 at 10:11
  • after running gradlew.bat clean build from the .gradle directory it showed the download progress, 6minutes in and still downloading jar files, thanks for the answer – Ameer Adel Nov 24 '20 at 10:45
  • This gave me error `Could not initialize class org.codehaus.groovy.reflection.ReflectionCache`, which I resolved with the help of [this answer](https://stackoverflow.com/a/64637310/6422750). – Theta Mar 03 '21 at 00:39
  • Is there any way, automatically downloading files from fast mirror (while it is downloading) – Md Rashedul Islam Sep 23 '21 at 17:31
  • This answer worked for me in that I discovered I didn't have my Java classpath set when running `gradlew clean`. – jvndev Sep 30 '21 at 07:43
  • Alright this worked fine for me but is there a way to fix this for every new Flutter project? – Usman Sabuwala Nov 27 '21 at 10:05
  • Getting No Such File or Directory – Jaimin Modi Jul 26 '22 at 05:08
  • why is it so slow ? It tales me 5 minutes for a project with 3 files... – Zhar Jul 31 '22 at 10:21
  • It works. FYI, whats helping is when you run `./gradlew clean build`, it gave us informations about the problem in android side, so you can fix it. In my case, i have to change SDK Version, due to library i installed. But, it took > 20 minutes for me – Muhammad Faisal Oct 07 '22 at 10:13
  • 4
    Now I got stuck too when running gradle clean. Lmfao. – zidniryi Nov 10 '22 at 15:08
  • step 5 is the best. always work for me – Waqas K Mar 15 '23 at 01:35
137

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à.
Sébastien
  • 13,831
  • 10
  • 55
  • 70
  • I was lazy to change anything, waited forever to see if it's gonna work and eventually it worked. So I guess it actually works, but as you said download speed is super slow. – Serjuice Sep 08 '20 at 07:00
  • 10
    By using this command I can see that the problem comes from downloading files.. It could be a good idea for flutter team to increase the default logging level, when the app is launched from Android Studio, the user has no clue about what's going on! Thanks for the tip :-) – funder7 Dec 15 '20 at 12:52
  • gradle got me every single time. Whenever I do new setup... I have to do this. – omer Feb 09 '21 at 17:08
  • 11
    flutter run -v this command made the day. You again proved Flutter has many built-in great debugging tools that we forgot to use – Varun Kumar Medam May 16 '21 at 18:57
  • after flutter run -v i noticed i was stuck because of invalid app id for admob in mainfest file , Thanks – Bijay Poudel Oct 15 '22 at 12:57
65

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!

20

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.

enriquenery
  • 201
  • 2
  • 3
18

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.

Aditya Thakur
  • 1,012
  • 1
  • 13
  • 20
  • "3. Go down to Flutter and click on the 'Open Android module in Android Studio' "But my ```Flutter``` is disabled. In another flutter project which can run sucessful, the ```Flutter``` is enabled. Do you know why? – Krahmal Dec 28 '21 at 03:58
  • It did show Flutter disabled in certain cases. In that instance, you can instead use the terminal to do this as mentioned in the answer: https://stackoverflow.com/a/60691179/11690853 – Aditya Thakur Dec 29 '21 at 04:07
  • Thank you. And I solved the problem by upgrade the ```compileSdkVersion``` to 31. The ```flutter``` is still disabled but it just doesn't matter. – Krahmal Dec 29 '21 at 05:10
10

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

briancollins081
  • 845
  • 9
  • 19
6

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

Wipe data by AVD Manager

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
5

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).
Paul Parker
  • 1,163
  • 12
  • 23
5

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.

Thrishool MSM
  • 337
  • 3
  • 11
4

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

flutter clean
Osvaldo Vb
  • 41
  • 1
4

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

Upulie Han
  • 431
  • 1
  • 7
  • 15
3

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.

Duncan Pullen
  • 355
  • 3
  • 13
3

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.

btd1337
  • 2,616
  • 2
  • 16
  • 25
2

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.

jibril90
  • 95
  • 1
  • 1
2

In Android Studio:

Tools -> Flutter -> Flutter clean.

After that just run the app

Alex Reye
  • 41
  • 4
2

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.

yung
  • 21
  • 1
2

1: If it is the first launch, please be patient since it will download all gradle files for the first time.

2: To know if it really stuck, take help from the task manager in windows or the activity monitor on Mac, and check if the process is really using some CPU or network or not. If not, it is stuck. If it is using some resources, please be patient then (it should take ~5-40 minutes normally, even if you have slower internet).

3: If it is really suck, stop the process and run ./gradlew clean before building it next time.

Rashid Wassan
  • 664
  • 5
  • 13
1

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

Alex
  • 21
  • 2
1

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

1

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.

Uday Chauhan
  • 1,071
  • 1
  • 9
  • 19
1

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.

1

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

Rishabh
  • 1,827
  • 1
  • 12
  • 9
1

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

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
1

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

Dayo Jaiye
  • 948
  • 1
  • 10
  • 17
1

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.

DARK_C0D3R
  • 2,075
  • 16
  • 21
1
  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!!

1

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

Eyayu Tefera
  • 771
  • 9
  • 9
1

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

Priyanka
  • 3,369
  • 1
  • 10
  • 33
1

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.

Mithson
  • 1,554
  • 13
  • 33
0

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

0

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

0

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

0

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.

0

In my case installing JDK solved the problem.

macOS Catlina v10.15.4

Mamad Farrahi
  • 394
  • 1
  • 5
  • 20
0

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.

grape100
  • 341
  • 4
  • 11
0

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

krylov123
  • 739
  • 8
  • 15
0

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.

Haileapp
  • 755
  • 7
  • 20
0

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.

Justin
  • 378
  • 1
  • 3
  • 12
0

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

Example:

~/New Folder/myProject

Check if you have this issue.

0

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

Yash Zade
  • 163
  • 1
  • 4
0

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

bounxye
  • 183
  • 5
  • 13
0

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

0

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.

Amina Bekir
  • 220
  • 2
  • 9
0

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.

Viroth
  • 429
  • 5
  • 14
0

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.

Jamal Azizbeigi
  • 135
  • 1
  • 14
0

Had this issue today, every solution I found didn't work. In my case, I had to update Windows, after installing every update they listed and then restarting pc, the problem disappeared.

Szomti
  • 57
  • 1
  • 9
0

I had the same issue for almost half a day, so what I did :

  • Go to my Home directory, enabled show hidden folders.
  • Delete the .gradle folder.
  • Went back to Android studio, opened the terminal, and ran the flutter run command.
  • After it completes, the app will be launched on your connected device.

Note: Make sure you have a strong internet connection because gradle files are going to be re-downloaded.

Thank you, hope this one helps

Joel Kanyi
  • 81
  • 1
  • 7
0

for me, I just changed my proxy, while I have problem on sync gradle files on my country.

moshen pejam
  • 43
  • 2
  • 7
0

In my case I just restart my computer and it's fixed. Probably it's happening because of lack of some files while launching the app.

D. S. Shatner
  • 40
  • 1
  • 6
0

I cannot edit other answeres so here is mine on top of answere from @Sébastien.

first use flutter run -v or of you are using Android Studio, edit project configurations and add -v to the Additional run args

after that running project shows that in my case gradle downloading is taking too much time, so download it directly and unzip it in: C:\Users\ <MyUsername>\.gradle\wrapper\dists\gradle-5.6.2-all\9st6wgf78h16so49nn74lgtbb

some notes about this address:

  1. gradle folder should be the same name as the file you downloaded so if it ends in bin instead of all, use that

  2. the hash at the end is created by default when graddle wrapper starts the download but these are some common ones on my system:

    gradle-7.1-bin:4pslxx9lrxt5svtz5wbnb6tkz

    gradle-7.2.1-all:2hmet7i3y4pg69r05wkkofsqn

    gradle-7.3.3-all:4295vidhdd9hd3gbjyw1xqxpo

    gradle-7.5-all:6qsw290k5lz422uaf8jf6m7co

    gradle-7.5.1-all:1ehga6e77gqps5uk2kc5kf1vc

NOTE inside the said folder there is a file ended in .part, that is the partially downloaded gradle file, if it is there gradlew will try to complete it, so change the .part to .ok, ex: gradle-7.5-all.zip.part -> gradle-7.5-all.zip.ok you can also delete it and use an empty file to save some space

mohas
  • 1,911
  • 1
  • 16
  • 20
-1

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

Bauroziq
  • 951
  • 9
  • 14
-1

On android studio go to file/invalidate caches/

For me this works

-3

taskkill /F /IM dart.exe then flutter clean

Mt Khalifa
  • 459
  • 1
  • 6
  • 20
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Tschallacka Jul 14 '20 at 14:01
  • I have tried all these methods but still it is stuck at assemble gradle debug. This issue never happened before. Please help – user24826 Jan 12 '22 at 12:46