Resolve Android Java VM error with Ionic/Cordova

Every once in a while, when I attempt to build my Ionic app for an android device, the process fails with this unhelpful mess of errors:

My analysis started with something like this:

Ok there's a daemon...keep reading...oh looks like its something about Java, of course its Java - its always Java. Ok its crashing...could not reserve enough space? 16GB of RAM isn't enough? And I have the latest version of that blasted program.

Against all rational advice, restarting does in fact fix the problem 98% of the time (verified statistic). But after a few more recent occurrences, restarting has gotten to be more annoying than actually fixing the problem.

Turns out, the problem in this case is that the android build process is targeting the 32-bit version of Java (see above picture). Or, more accurately, the windows environment variable is targeting the wrong version. Wait, I didn't install the 32-bit version. Who does that in 2015? A little googling revealed that the 32-bit version is often installed as part of other programs, such as Visual Studio.

The fix is rather simple, we just need to point the environment variable to the 64-bit version. Go to System Properties > Advanced System Settings and hit Environment Variables. Under System Variables, hit "New". Add a variable called JAVA_HOME and set the correct path - something like C:\Program Files\Java\jdk1.8.0_71. Now, restart and try again.

Brandon Brown

Read more posts by this author.