Error when compiling Android

Hello everyone,

I’m running Unity 4.6 in OS X 10.9.5, and I’m getting the following error when I try to compile to android:

Failed to compile resources with the following parameters:
-bootclasspath "/Users/ines/Development/android-sdk-macosx/platforms/android-21/android.jar" -d "/Users/ines/Documents/Game/Temp/StagingArea/bin/classes" -source 1.6 -target 1.6 -encoding UTF-8 "com/Company/Game/R.java" "com/facebook/android/R.java"
warning: java/lang/Object.class(java/lang:Object.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.

Does anyone know how I can solve this problem?

Thank you guys. I’ve found the solution.

Steps to make this work:

  1. Set the JAVA_HOME environment value:

export JAVA_HOME= ` /usr/libexec/java_home `

  1. Add the java bin folder to the PATH variable:

export PATH=$JAVA_HOME/bin:$PATH

  1. Create a link in the following directory:

sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents \ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

And that’s it. Hope it helps.

For people who doesn’t have new JDK version

  1. download JDK of mac os x : https://jdk8.java.net/download.html
  2. sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

It probably means Unity is running a Java compiler of some version and a JRE of a different (higher) version.

The compiler complains that it can only support version 50, but you are using version 51.

Check whether you have multiple Java installations on your machine, and the environment variables that you set.

Either leave only 1 installation, or make sure that Unity will use the correct JDK and JRE by setting the environment variables correctly.

After upgrading my Android SDK version, I was having this error. I followed all the steps outlined for changing default Java version, environment, etc. I installed newest version of JDK (8), still nothing. I found that I needed to uninstall JDK 6 as final step to get everything to work again.