Before you read
If you’re in a hurry, please access the quick sumary below. Otherwise, please continue reading starting next line.
What’s up, doctor ?
There are some tricks that are so obvious and easy to do that you ask yourself, when done : « Why didn’t I do it before ? ». The following one is this kind of trick.
When building your yet-to-be blockbuster App for Android with Qt, your favourite IDE, QtCreator, complains that :
To honour the JVM settings for this build a new JVM will be forked.
Well, it says so because you run Gradle to build your App, and you probably ask it something uncommon for the JVM. Like this, through
Therefore, if your default maximum memory size for your current JVM is not big enough, Gradle obeys your command and starts a new JVM in which it will be launched again.
If you do not set the option, it will complain that you didn’t like this :
:transformClassesWithDexForDebug Running dex as a separate process. To run dex in process, the Gradle daemon needs a larger heap. It currently has 1024 MB. For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB. To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties. For more information see https://docs.gradle.org/current/userguide/build_environment.html
Oh, so you’ve set the option for a reason, at least. You have to comment it out.
There is a very simple way to avoid launching another JVM. What would you want to do that ? Because it slows down your Java building part (compilation of Java code and package generation).
You just have to configure the JVM with your default options. But how exactly do you achieve this ? On Windows. Version 7. Yes, I like it the weird way.
I won’t list all the possible ways to fail acheiving it. But I’d like to point out a few.
No, setting the option in the dedicated field in the Java Control Panel won’t work. At least I didn’t manage to make it work.
Does setting the correct environment variable with the option works ? No. Setting
has strictly no positive (neither negative AFAIK) effect on your build.
The right way to do it, is to look at the Gradle wrapper in your project directory and read this comment :
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
JAVA_BLABLA environment variable. So I set the
GRADLE_OPTS, through the Control Panel, and restarted QtCreator to observe that it did not change a thing. It doesn’t work. Same warning reported by Dex.
A bit fed up, I modified
gradlew.bat like the rookie I am and… it worked [random smiling emoji].
Actually, before doing this, my aim was to launch the Gradle daemon, in order to have quicker APK generation. But I figured it out to be pointless, as it won’t be used by QtCreator, as I understand.
Maybe there is a solution using both Qt Creator and Android Studio, but I’ve no more time to spare in looking for it.
To avoid having Gradle launching another JVM during the generation of an APK, modify your
gradlew.bat file in the directory of your project and change
Generally speaking, comment out the line setting
gradle.properties and copy the options it contained directly in