packageDebug Error - Java Heap Space with Large SQLite DB

Hello -

I have a large populated SQLite DB file (900MB) that is the core of an application I’ve developed.

It compiles for iOS without any issues or errors.

When compiling it for android, I am getting the following error:

:packageDebug
 FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':packageDebug'.
> Java heap space
* Try:
BUILD FAILED
Total time: 2.773 secs
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: /Users/Matt/dropbox/dgprivate/purinaola/ionic/purinaola/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':packageDebug'.
> Java heap space
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I’ve tried various approaches to increasing the heap size for Gradle including:

  • creating a gradle.properties file in the ~/.gradle
  • modifying gradle.properties in the platforms/android folder
  • adding environment variable GRADLE_OPTS=-Xmx2048m
  • adding environment variable DEFAULT_JVM_OPTS=-Xmx2048m

Any suggestions would be greatly appreciated - including ways to verify what the actual heap size is for Gradle when performing an ionic build.

Having the same problem since I upgraded my build environment. (Building with large pre-filled db used to work). Did you find a solution ?

Hi Kurt -

Not a solution as much as a work around. I ultimately had to shrink the database by being more selective with my field contents.

Indexes also took up a lot of space so I had the app generate them after it loaded.

Like I said - a workaround, not a fix.

I found that none of the switches or settings that were recommended for adjusting the heap size did anything.

I find it very difficult to tell which setting and/or switch ultimately applies to the build. The lack of cohesive and comprehensive documentation has relegated Ionic to very specific use cases for me.

Matt

What you are having problems with is the build process executed by Cordova. You might have more luck searching with “Cordova” instead of “Ionic” as Ionic only “proxies” the call to the Cordova CLI that then uses e.g. the Android SDK to build the app.

Thanks Jan -

That’s a good suggestion. The challenge is that each component in the series of proxies is unaware of being used as a proxy by the overall process. So each set of documentation exists independently, with no reference to the other parts.

The Ionic to Cordova to Android SDK build process makes it very difficult to trouble shoot a configuration setting that is being passed from Ionic through the aforementioned proxy chain.

In this case, I tried adjusting the settings all through the build pipeline but gave up when I couldn’t determine where the actual applied setting was coming from and nothing made any difference.

Any insight into this heap size setting problem would be appreciated.

Matt

To be honest I could never help anybody with heap issues yet as I have no experience with them.

But I know that Ionic CLI literally just calls cordova build android - so if you do so yourself you should get the exact same error message as with ionic cordova build android.

I managed to fix my build with the tip from @Sujan12.
running cordova build android -d shows that no matter what you have in gradle.properties or environment, the build get’s executed with -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true

The Cordova file ./platforms/android/cordova/lib/builders/GradleBuilder.js in the project folder
is responsible for hardcoding the maximum heap size:

    // to allow dex in process
    args.push('-Dorg.gradle.jvmargs=-Xmx2048m');

Increasing the maximum heap to 4g made my build successful.
Good Luck.

1 Like

That’s fantastic.

Thanks for the update. I really appreciate it.

Matt

2 Likes

Wow, awesome - thanks for digging in and figuring this out!

I created an issue with Cordova for that so maybe this will be modified to be easier to change: https://issues.apache.org/jira/browse/CB-12916

1 Like

I was running into this same problem but your workaround of increasing heap size to 4g basically told me that that heap size to too big. Hmm.

Turns out I was running JDK 1.8 (32 bit) instead of 64 bit. Some older software was requiring 32 bit. I read somewhere that the heap size limit on 32 bit is 1-1.5g and 64 bit is limited to total free memory.

So after updating JDK to 64bit and following above workarounds, all is well!!!

Thanks for such great documentation.