keeganwitt / docker-gradle

Docker images with Gradle
https://hub.docker.com/_/gradle/
Apache License 2.0
143 stars 73 forks source link

Extremely slow Android/Gradle building #285

Closed rwarner closed 4 months ago

rwarner commented 4 months ago

Hey thanks for making this docker image and efforts on it thus far. I've been working on trying to get our project building within the docker-gradle image. However, I'm facing extremely lengthy building times and am looking for advice.

I've made a custom image installing the Android SDK (command line tools for linux) and NodeJS and have been using a CI Pipeline to put our git repository in it and compile it into an APK.

However, I've been looking at 1 - 2 hr builds for a 3 module project.

Typically on my M1 Mac, I'm seeing Gradle build times running gradle assembleDev --profile with Azul JDK 17 take:

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.parallel=false

BUILD SUCCESSFUL in 2m 2s 163 actionable tasks: 141 executed, 22 up-to-date

or

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.daemon=true
org.gradle.caching=true

BUILD SUCCESSFUL in 1m 4s 163 actionable tasks: 132 executed, 13 from cache, 18 up-to-date

Using 8.7-jdk17-jammy I am seeing a successful build now, after:

org.gradle.daemon=true
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.vfs.watch=true

Have gotten it down to:

BUILD SUCCESSFUL in 58m 50s 163 actionable tasks: 145 executed, 18 from cache

I have tried every iteration of these GRADLE_OPTS and while build-cache and configuration-cache have helped a small amount. Nothing here seems to get it to build a reasonable amount of time. I have also tried disabling org.gradle.vfs.watch since it seems like the container filesystem does not support it when I look at the logs with gradle --i assembleDev.

I have also tried the alpine images as well, but needed to include Gcompat since AAPT2 was incompatible with the included C libraries, but that image was even slower.

I'm running out of other things to consider and have been poking around with this for days! Appreciate any assistance. Thanks

keeganwitt commented 4 months ago

What docker command are you running? Are you using any volume mounts?

rwarner commented 4 months ago

Hey Keegan, sorry for any confusion this may have caused. One last thing I looked into was the consideration of our shared gitlab runner and it's performance. (I was unaware of the limited hardware constraints it had with ram especially)

We ended up giving it a run on another gitlab runner with a lot more ram and cpu available and it is now completing extremely fast:

BUILD SUCCESSFUL in 3m 40s
163 actionable tasks: 146 executed, 17 from cache

So it was the machine the whole time!

keeganwitt commented 4 months ago

No worries, there's a lot of things that can impact the performance. Glad you got it figured out!