Table of contents

Android Studio build: Execution failed for task ':app:packageRelease'. java.lang.OutOfMemoryError

Android Oct 15, 2021 Viewed 2.1K Comments 0

Issue

To generate a signed Apk in Android Studio, I click Build -> Generate Signed Bundle / APK... . But there is an error when building.

Execution failed for task ':app:packageRelease'.
> A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
   > java.lang.OutOfMemoryError (no error message)

Solution

Edit the gradle.properties file in the Android project, add or update the heap size of jvm argument:

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx4g

It can be 2g, if OutOfMemoryError still occurs, try 4g again, and so on.

Updated Oct 15, 2021