10

I am getting this error in Android Studio logs when I am trying to build an APK.

Error:Execution failed for task ':app:packageDebug'. Java heap space

This issue is coming when I am trying to build an APK with 350 MB size of .sqlite in assets directory. When I removed the .sqlite file then issue is gone.

My studio64.exe.vmoptions file for studio:

-Xms2048m
-Xmx3840m
-XX:ReservedCodeCacheSize=960m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=250
-da
-Djna.nosys=true
-Djna.boot.library.path=

-Djna.debug_load=true
-Djna.debug_load.jna=true
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Didea.paths.selector=AndroidStudio2.3
-Didea.platform.prefix=AndroidStudio
-Didea.jre.check=true

enter image description here

Ready Android
  • 3,529
  • 2
  • 26
  • 40
  • 1
    Have you solved this? I have a huge mp4 file and keep getting this error too. I have also found this stackoverflow question here, perhaps it can help: https://stackoverflow.com/questions/41645747/android-studio-gradle-build-failing-java-heap-space/41685614 – Curious Mind Feb 23 '18 at 12:15
  • It doesn't help me as I already tried with @fluffyBatman answer. – Ready Android Feb 24 '18 at 10:41

2 Answers2

29

Add this at the end of gradle.properties file.

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
fluffyBatman
  • 6,524
  • 3
  • 24
  • 25
0

clean the project and try again

On root folder

cd android

./gradlew clean

cd ..

react-native run-android

Rahul Shakya
  • 1,269
  • 15
  • 15