Is there a legitimate way of Gradle task(s) execution stopping in Android Studio?
-
1I'm having the same issue as of May 2016. And then it goes OutOfMemoryException, even when the heap space is set to "4g" – ticofab May 16 '16 at 08:38
16 Answers
You can call ./gradlew --stop
in a terminal and it will kill all Gradle processes.

- 30,738
- 21
- 105
- 131

- 3,581
- 2
- 15
- 17
-
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain – kartikag01 Sep 05 '16 at 18:23
-
2Works well to force stop any gradle process, no matter which step is currently running. It's a shame that (as of Android Studio 2.2.2) the "stop" button in AS is not able to achieve the same thing... – Sébastien Nov 07 '16 at 15:20
-
1i got a permission denied, even when running with root, on then mac. – MiguelSlv Jan 18 '17 at 18:27
-
1that does not help in case the gradle is hanging up, only killing the process of Android Studio and then restarting it helps – Alexey Timokhin Aug 11 '17 at 16:55
No, Gradle (as of this writing, v1.10) has a limitation that you can't cancel tasks through its tooling API, which is what Android Studio uses to communicate with its daemon. You can track the progress of this at https://code.google.com/p/android/issues/detail?id=59464 . It's also preventing progress on something else we'd like to be able to do, https://code.google.com/p/android/issues/detail?id=59965
In the meantime about all you can do is to go through your OS and kill the Gradle processes manually, which is a little painful and messy. It's possible that it could leave your build in some intermediate bad state which would mess up future incremental compiles, but I don't know for sure.

- 79,344
- 24
- 180
- 163
-
50In that case, they should not give a Cancel button while executing gradle tasks. – Tushar Kathuria Oct 15 '15 at 17:17
-
5Even if the issue was marked as "released" on Dec 2014, as of Nov 2015 I still have this very same bug. OMG, Android Studio is just horrendous. – Eduardo Nov 08 '15 at 01:38
-
-
6It's June 2016 and the Cancel still doesn't work as expected. In the thread mentioned in this answer they say they've implemented fixes for that, but I don't see a big difference in practice... – Stan Jun 13 '16 at 12:02
-
-
With Android Studio 1.3.2 a kill button appears when the gradle is building on the very bottom of the IDE screen.
It doesn't seem to do anything, but at least there's something to push. Wheee! :D

- 11,034
- 6
- 68
- 83
-
16android studio overall does a lot of bullshit that cant be turned off.. – Siddharth Jul 01 '16 at 07:12
-
7
-
1
-
For me both 'gradlew --stop' command in the terminal and kill button in the bottom as shown by @Scott Biggs, worked.Thank you. Note: I didn't use './' before 'gradlew --stop' command. – Shashi Shiva L Jul 21 '19 at 04:40
Quitting Android studio is another way it'll kill the gradle daemon or if it's hung deploying to Android device unplugging the device can halt the process (neither are ideal solutions)

- 23,621
- 16
- 94
- 105
-
1Well my AS will stop functioning on quit when a Gradle task is running. It still seems responsive but it does not update the window, – Madmenyo Dec 25 '15 at 13:55
Thanks to Rami Kuret and Flavio Faria.
You can call .\gradlew --stop in a Terminal and it will kill all Gradle processes in Android Studio for Windows OS.
You can find the terminal at the left bottom of your Android Studio for Windows.

- 30,738
- 21
- 105
- 131

- 507
- 5
- 7
This is just something quick I found out. If you want to end the process, you can also:
- Go into Task Manager by right-clicking the taskbar then going to "Task Manager" or simply by Ctrl + Shift + Esc
- Then ending the Java process that's running.

- 30,738
- 21
- 105
- 131

- 4,151
- 10
- 57
- 117
When every other method fails just use:
ps -A | grep gradle | awk '{ print $1; }' | xargs kill -9
to get the list of every process with a 'gradle' keywork and kill it forcefully.

- 10,922
- 12
- 70
- 83
I know this is an old question but now with Android Studio 1.2, you can cancel current gradle task by quitting Android Studio, it'll open a Confirm exit dilog says there's a background running task, choose Exit, then there will be another dialog to cancel background task, choose Yes and gradle task will be canceled without quitting studio.
Remember to clean project before run other build task, or something might be messed up.
(I'm on Mac OS X)

- 1,782
- 1
- 17
- 32
-
On Windows it's similar. Quit Android Studio when gradle is running, answer "Exit", then answer "No". After that a gradle will stop compiling. – CoolMind Oct 15 '15 at 11:56
-
2@CoolMind lately, if I do so, Android Studio freeze and show a black screen. I even have to reboot Windows for it to compile again... – Dan Chaltiel Dec 06 '15 at 13:05
-
@DanChaltiel, maybe, it happens sometimes (at my computer Android Studio hasn't freezed). Did you clean and rebuild a project after stopping gradle? Or Android Studio doesn't allow this? Sorry, if this bug remains. – CoolMind Dec 06 '15 at 14:36
-
@CoolMind Thx for replying, I even made a [question about this](http://stackoverflow.com/questions/34118223/android-studio-1-5-1-cannot-build). – Dan Chaltiel Dec 06 '15 at 15:05
-
@DanChaltiel hm, it looks like Stankovitch recommended there to install 2 Android Studios. Sorry for a question, may a problem be in Java? – CoolMind Dec 06 '15 at 15:35
-
@CoolMind nop, everything was fine a moment ago. I'm trying some ORM libraries though, but sometimes they build. The new version of Android studio didn't resolve anything. – Dan Chaltiel Dec 06 '15 at 16:31
Just execute .\gradlew --stop
in the terminal which is located on the bottom of the Android Studio. After it kills the Gradle process, clean the project and rerun the project.
See the image for more information:

- 30,738
- 21
- 105
- 131

- 1,562
- 1
- 17
- 28
There is an Android Studio plugin for that: GradleStop
It will just add a "gradle stop" command and menu item which will call ./gradlew --stop
.

- 30,738
- 21
- 105
- 131

- 560
- 9
- 21
Not a "legitimate" way but this is what i do.
- Click on Gradle Sync while your build process is ongoing.
- Android Studio will warn you with something like "Continue with Project Closing?". Click yes.
The build process will be cancelled and the gradle Sync operation will begin which is relatively quicker (as compared to waiting for the whole build process to complete, as i have a project with MANY library modules)

- 9,912
- 8
- 41
- 47
The way I solved this was:
Go to your project → graddle-wrapper.properties (Gradle version)
Then edit the distributionURl to the version you want. Here's a picture:

- 30,738
- 21
- 105
- 131

- 501
- 2
- 6
- 18
There are two easy existing ways to stop it without killing the process.
The first one is that you load two projects with Android Studio, and when you close your project, the Gradle building project, it will close immediately.
The second one is simply click on the file and click Close project and it will stop instantly.
The benefits of these method is you don't need to wait too much to start Android Studio again.

- 30,738
- 21
- 105
- 131

- 20,623
- 10
- 57
- 53
Kill the studio.exe process from Task Manager and then restart your machine. This is the only thing that is working for me.
If you kill every related process and don't restart the machine, you can't run or build your app because it will say "Another gradle instance running".

- 30,738
- 21
- 105
- 131

- 101
- 11
As of Android Studio 3.0, the little red cross button next to the Gradle build status indicator bar seems to be working!

- 30,738
- 21
- 105
- 131

- 131
- 5
On Windows, go to the Run dialog by pressing Windows + R and type taskkill /f /im studio64.exe
. That will kill Android Studio and stop Gradle.

- 30,738
- 21
- 105
- 131

- 69
- 2
- 2