Advertisement
Intermediate .NET MAUI, Troubleshooting & Common Errors

How do you fix 'Java heap space'/build OutOfMemory errors on Android?

Short answer

Increase the Java max heap for the Android build (JavaMaximumHeapSize), enable D8/R8 and resource shrinking, disable multidex issues, and ensure you're not bundling excessive assets. For large apps, enable AndroidLinkMode and reduce ABIs during debug to speed and lighten builds.

Save .NET MAUI mock interview
Advertisement
AModel answer
Increase the Java max heap for the Android build (JavaMaximumHeapSize), enable D8/R8 and resource shrinking, disable multidex issues, and ensure you're not bundling excessive assets. For large apps, enable AndroidLinkMode and reduce ABIs during debug to speed and lighten builds.
<PropertyGroup>
    <JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
    <AndroidEnableMultiDex>true</AndroidEnableMultiDex>
</PropertyGroup>
Real-world example
A CI Android build stops failing after raising the Java heap size and enabling R8 shrinking.
Likely follow-ups
  • What does R8 do? | Why limit ABIs in debug?
Related topics