Gradle daemon disappeared unexpectedly

On upgrade to AGP 8 from AGP 7.3, I am seeing the below error many time for a lot of gradle tasks in CU runs: unit tests or assemble release builds. The same tasks run successfully sometimes and the failures don’t happen at the same gradle sub-step.

Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)

On searching the internet, most solutions point to increasing the heap size or deleting the .gradle folder. I have tried them with no success unfortunately.

If you have any pointers on how I can proceed further, please share.

1 Like

Look in the logs of the daemon whether you find anything suspicious, and in the logs of the operating system.
Often - especially on Linux - the OOM killer has the opinion the process needs too much RAM and kills it.
This manifests in exactly the same behavior you described and specifying more heap will just make it worse.

1 Like

I couldn’t get hold of those logs. However, I changed the maximum heap size given to gradle tasks from 28GB to 18 GB and it started working. Do you know any theory behind that ?

My guess would be, that the daemon then just consumed more ram than available in the system, or said OOM killer got the impression the process is too greedy and killed it and by giving it less max heap this fixed it. Java tries to about unnecessary garbage collections and so on, so if you tell it it is allowed to take that much heap, it eventually will do it.

2 Likes

Thanks for your reply @Vampire .

1 Like