I kept on getting this error when building for Android (shadow demo):
Building DEX Failed!
G:\Unity\JavaPluginSample\Temp/StagingArea> java -Xmx1024M
-Djava.ext.dirs="G:/AndroidSDK/android-sdk_r09-windows\platform-tools/lib/"
-jar "G:/AndroidSDK/android-sdk_r09-windows\platform-tools/lib/dx.jar"
--dex --verbose --output=bin/classes.dex bin/classes.jar plugins
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Well, I tried uninstalling and updating both the JDK and JRE. I still kept on getting the error. I finally fixed it by modifying the Xmx variable of java. I noticed that Unity3d uses a value of 1024Mb and this is the cause of the problem, at least on my PC (4gb, winXP32) because on my laptop (1gb, winXP32) it works fine without modifying anything.
Anyway, here is how to fix it:
Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System Variables->New:
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M
If 512Mb doesn’t work, try reducing it from 1024 to lower until it works. Also, when googling around I noticed that some users reported that the order in which the path variables occur makes a difference too. The JRE must be the first one. I am not sure if this is true, but here it is anyway:
Variable name: Path
Variable value: ;C:\Program Files\Java\jre6\bin;F:\JDK\bin;
Change this to your appropriate path.
I tried unity on a new laptop now. It has Windows 7 and 2gb memory. It has a fresh install (format before) of all the required components yet the same problem exists. I now use unity 3.3 instead of 3.2 but it makes no difference. The fix above solves the problem.
The interesting thing is that the fix above breaks java on my XP 4gb machine. If I open my browser (any), it crashes if I open a webpage which uses java. It works fine on my windows 7 laptop. Weird…
Unity needs to address this issue. The excuse that the problem is caused by a bad installation of java is just plain nonsense. At least in my case. How can this be, on two completely different systems, one with a fresh install of everything?
I just purchased and imported GyroDroid into a new Unity 3.5.6f4 project on a WinXP SP3 machine. I have the latest JRE6 installed. When I try to build the project for Android, I get the error indicated above. When I try the fix listed above by creating a _JAVA_OPTIONS env var using a value of -Xmx512m the compile appears to work, but then errors when trying to sign the package, even though the correct passwords in the publishing settings.
arsigner: unable to read password: The handle is invalid
Enter Passphrase for keystore: Picked up _JAVA_OPTIONS: -Xmx512m
If I use the _JAVA_OPTIONS, do all parameters have to be picked up from the env var?
Is there another way of setting this java compiler setting in a Unity config file or something?
Hi to all, I am new in Unity and I am trying to export a very simple test project to Android. I have done everything mentioned in this thread but I still get the invokation error (it says something about Java language Null exception or something) when Unity tries to communicate with Android SDK. My OS is Win64 but the JRE and JDK is for Win32 like the latest Unity version I have installed in my PC. Any help will be much appreciated. Thanks.
I upgraded to Win 7 64 bit and at first everything worked smoothly. Then for no particular reason this error started to show up again. Interestingly Unity had lost the Android SDK folder as previously mentioned. However, setting the Android SDK folder again didn’t work as Unity lost it every time.
Restarted computer, started Unity, set path, closed Unity, started Unity again and now it works.
There is something seriously wrong with either Java or Unity.