Search code examples
androidgradleheap-size

Heap Space Size?


I have a db file(300mb) in my assets folder.When I am running the code it gives me below error

Error:Execution failed for task ':app:packageDebug'.
> Java heap space
ect's gradle.properties file.
For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
<em>org.gradle.jvmargs=-Xmx1024m</em>
<a href="http://www.gradle.org/docs/current/userguide/build_environment.html">Read Gradle's configuration guide</a><br><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html">Read about Java's heap size</a>

Below is gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.


# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true


org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

I tried lot of things like changing _JAVA_OPTIONS in environment variable, Changing values in studio.exe.vmoptions and gradle.properties but it is giving me the same error.

Please help


Solution

  • Try increasing java heap size. Here are the steps:

    Look for memory indicator in bottom right corner of Android Studio

    enter image description here

    If you don't see this option, enable it from Android Studio Preferences > Appearance and Behaviour > Appearance > Show memory indicator

    enter image description here

    Increase java heap size: Choose Help > Edit custom VM Options

    enter image description here

    Update Xmx value in studio.vmoptions file that open when you select above option. For 8GB RAM I have added these values, you might need to adjust based on your system configuration:

    -Xmx4096m
    -XX:MaxPermSize=1024m
    

    You can also find this file in ~/Library/Preferences/AndroidStudio

    Restart Android Studio and see if your memory indicator displays updated values.