assembleDebug runs out of memory when rebuilding all examples
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- build-system
Research direction
The fix is configuration, so start in gradle.properties (the org.gradle.jvmargs=-Xmx4096m heap and where worker limits would go) and check settings.gradle.kts. The failing task is mergeExtDexDebug in the example modules, such as examples:Example04Polylines. Reproduce with ./gradlew --stop then ./gradlew assembleDebug --rerun-tasks. Done means that command succeeds without --max-workers. Confirm with the maintainer which of the two proposed fixes to take, since raising the heap and capping workers trade off differently.
Written by the indexing model from the issue text.
Description
A full rebuild of the example apps fails with OutOfMemoryError: Java heap space in the Gradle daemon on machines with many CPU cores.
Steps to reproduce
./gradlew --stop
./gradlew assembleDebug --rerun-tasks
On a 14-core Mac this fails after about 15 seconds, usually in mergeExtDexDebug of one or more examples:
> Task :examples:Example04Polylines:mergeExtDexDebug FAILED
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Caused by: java.lang.OutOfMemoryError: Java heap space
After the failure the daemon can be left in a broken state ("Cannot lock file hash cache ... already been locked by this process"), so ./gradlew --stop is needed before the next build.
The same failure also happens without --rerun-tasks whenever all examples need to be rebuilt, for example after a change in the library or in settings.gradle.kts. Incremental builds are not affected.
Cause
All 12 example apps run dex merging in parallel inside the Gradle daemon. The number of parallel workers defaults to the number of CPU cores, but the daemon heap is limited to 4 GB (org.gradle.jvmargs=-Xmx4096m in gradle.properties). CI is not affected because its runners have fewer cores.
Limiting the workers avoids the problem:
./gradlew --stop
./gradlew assembleDebug --rerun-tasks --max-workers=4 # BUILD SUCCESSFUL
Possible fixes
- Increase the daemon heap in
gradle.properties, for example-Xmx6g - Or limit parallelism with
org.gradle.workers.maxingradle.properties
- Dominant language
- Kotlin
- Stars
- 4
- Forks
- 1
- Avg merge
- 1h 6m
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from afarber/OpenMapView
-
enhancement
Difficulty 2/5 Under an hour Newbie friendliness 72/100
afarber/OpenMapView#22 ·
-
documentation good first issue
Difficulty 1/5 Under an hour Newbie friendliness 85/100
afarber/OpenMapView#21 ·
-
Upgrade ktlintOpenenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
afarber/OpenMapView#20 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
afarber/OpenMapView#18 ·
All issues in afarber/OpenMapView
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ankidroid/Anki-Android#22408 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
nightscout/AndroidAPS#5245 ·
Maintainers usually reply within 1 day
-
Feature:Resolution
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
intellij-elixir/intellij-elixir#4396 ·
Maintainers usually reply within 1 day
-
s: need triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Tencent-TDS/KuiklyUI#1786 ·
Maintainers usually reply within 1 day