115

Is there a legitimate way of Gradle task(s) execution stopping in Android Studio?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eugene
  • 59,186
  • 91
  • 226
  • 333
  • 1
    I'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 Answers16

174

You can call ./gradlew --stop in a terminal and it will kill all Gradle processes.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rami Kuret
  • 3,581
  • 2
  • 15
  • 17
  • Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain – kartikag01 Sep 05 '16 at 18:23
  • 2
    Works 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
  • 1
    i got a permission denied, even when running with root, on then mac. – MiguelSlv Jan 18 '17 at 18:27
  • 1
    that 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
48

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.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
36

With Android Studio 1.3.2 a kill button appears when the gradle is building on the very bottom of the IDE screen.

build kill button

It doesn't seem to do anything, but at least there's something to push. Wheee! :D

SMBiggs
  • 11,034
  • 6
  • 68
  • 83
9

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)

scottyab
  • 23,621
  • 16
  • 94
  • 105
  • 1
    Well 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
7

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.

Screenshot of ...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ajay Yadiki
  • 507
  • 5
  • 7
5

This is just something quick I found out. If you want to end the process, you can also:

  1. Go into Task Manager by right-clicking the taskbar then going to "Task Manager" or simply by Ctrl + Shift + Esc
  2. Then ending the Java process that's running.

image

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
5

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.

4

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)

kientux
  • 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
3

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:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ravi Vaniya
  • 1,562
  • 1
  • 17
  • 28
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Someone
  • 560
  • 9
  • 21
0

Not a "legitimate" way but this is what i do.

  1. Click on Gradle Sync while your build process is ongoing.
  2. 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)

Vinay W
  • 9,912
  • 8
  • 41
  • 47
0

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:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Antuan
  • 501
  • 2
  • 6
  • 18
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amir Hossein Ghasemi
  • 20,623
  • 10
  • 57
  • 53
0

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Silent Coder
  • 101
  • 11
0

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
FJJ
  • 131
  • 5
-1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131