Wednesday, April 2, 2014

unity3d and facebook sdk problem - Error building Player: Win32Exception: ApplicationName='C:\Program Files (x86)\Java\jre7\bin\javac.exe',

If you are going to use facebook SDK for unity3d, then you will get these problems.

If you come across with this error: 
Error building Player: Win32Exception: ApplicationName='C:\Program Files (x86)\Java\jre7\bin\javac.exe',

then you only have Java JRE which does not come with javac.exe. You must install JAVA JDK from java website . Also be sure to read about  PATH Environment Variable (Optional) on java documentation page.  

You need JAVA JDK ! Not JRE !



here is the way to set environment table for java path: 
C:\> "C:\Program Files\Java\jdk1.7.0\bin\javac" MyClass.java
It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.7.0\bin directory to the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.7.0\bin. Set the PATH variable as follows on Microsoft Windows:
  1. Click Start, then Control Panel, then System.
  2. Click Advanced, then Environment Variables.
  3. Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable:
    C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0\bin
Note:
  • The PATH environment variable is a series of directories separated by semicolons (;) and is not case-sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
  • You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored.
  • If you are not sure where to add the path, add it to the right of the value of the PATH variable.
  • The new path takes effect in each new command window you open after setting the PATH variable.


also you may have to set JAVA_HOME to the directory on your machine that does have JDK (and javac.exe) installed.


here is a step by step how to change JAVA_HOME directory:

Set the JAVA_HOME Variable
Once you have the JDK installation path:
  1. Right-click the My Computer icon on
  2. your desktop and select Properties.
  3. Click the Advanced tab. Click the
  4. Environment Variables button. Under System Variables, click New.
  5. Enter the variable name as JAVA_HOME.
  6. Enter the variable value as the installation path for the Java Development Kit.
  7. Click OK.
  8. Click Apply Changes.
You might need to restart windows.
NOTE: You have to put the path to the jdk without /bin in the end.
For example:  C:\Java\jdk1.6.0_44 , NOT C:\Java\jdk1.6.0_44\bin.

You have to restart Unity3D so that unity can read the new java home path. After this you can build your unity3d game with facebook sdk without any problems.



Btw, if you need openssl for windows to create keystore for facebook sdk for unity3d, you must first download openssl and extrac its bin folder content to C:\Program Files\Java\jdk1.8.0\bin (or whereever you java install dir is) then add C:\Program Files\Java\jdk1.8.0\bin to enviroment path.

and to create keystore: 

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | penssl.exe sha1 -binary | openssl.exe base64



and the SECOND common problem is this error: 
... your android debug keystore file is missing ...

This second problem is  EASY  to fix. 
This happens when your your Unity project is on another drive than C: drive. Anyway this is not a problem. You need to fix a c# script in facebook directory in your unity project panel. Locate Facebook>Android>FacebookAndroidUtil cd file.  Open file. Find this row: 
System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" : 
and change it with this one: 
System.Environment.GetEnvironmentVariable("HOMEDRIVE") + System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" :

save the file. and restart unity3d. you will see that your problems will go away :) 

2 comments: