0
votes

cordova build tells me the following

To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB. For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB. To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties. For more information see https://docs.gradle.org/current/userguide/build_environment.html

how can I set the jvmargs to -xmx2084M in cordova? Is it possible through config.xml or do I have to use hooks?

Cheers & Thanks

Qiong

2

2 Answers

1
votes

Qiong
You nee to put a file named build-extras.gradlein your platforms/android folder. Cordova will read the file automatically and will load the configuration for you.
You can do this manually or by a hook. The problem of the first option is that if you erase your platform folder, the will be erased as well.

The content of the file specifies the maximum heap size:

android {
  dexOptions {
    javaMaxHeapSize "2048m"
  }
}

If you want to go with the hook option, the content of the should be like this:

#!/usr/bin/env node
'use strict';
var fs = require('fs');
var rootdir = process.argv[2];
if(fs.existsSync(rootdir + '/platforms/android')){
  console.log('Add build-extras.gradle');
  fs.createReadStream(rootdir + '/build-extras.gradle').pipe(fs.createWriteStream(rootdir + '/platforms/android/build-extras.gradle'));
}

And you need to put the file on hooks/after_prepare/ folder. This will run your hook automatically.

0
votes

Try setting this environment variable before starting the gradle daemon

export GRADLE_OPTS=-Xmx2g

edit

Wait.. why can you not just do what the message says?

set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties