Resource compilation failed! Failed to recompile android resource files. See the Console for details.

I’m working on adding Google Play Game Services to a Unity project.

Started getting these errors recently, however not sure if it is because of the Game Services, or could be I updated my machine.

The following in Console output:

Failed to compile resources with the
following parameters: -bootclasspath
“/Users/alex/development/adt-bundle-mac-x86_64-20131030/sdk/platforms/android-21/android.jar”
-d “/Users/alex/Documents/development/unity/Maze/Maze/Temp/StagingArea/bin/classes”
-source 1.6 -target 1.6 -encoding UTF-8 “com/facebook/android/R.java”
“com/google/android/gms/R.java”
“com/google/example/games/basegameutils/R.java”
“com/google/example/games/mainlibproj/R.java”
“com/mildspring/maze/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. 1 warning

UnityEditor.HostView:OnGUI()

Error building Player: UnityException:
Resource compilation failed! Failed to
recompile android resource files. See
the Console for details.

You have not installed jdk 1.7 yet or has been installed but did not set Path correctly.

  • Open Terminal, run:

    open ~/.bash_profile
    
  • Add these lines into bash_profile:

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin
    export PATH=$JAVA_HOME/bin:$PATH

  • Run this command:

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

*NOTE: You should not just copy all of these commands, use your path instead. (For example, my path is jdk1.7.0_71.jdk because my jdk version is jdk7u71, if your version is difference, your path will be difference)

For anyone else who ends up here: As of Unity 2017, Unity is incompatible with JDK 9. You need to continue to use JDK 1.8 for the time being.

In my case JDK was installed but Unity was pointing to an older version causing the same error.

I just got the same issue using 5.6.3p2 and jdk 1.10. Which is the actual, compatible jdk? Or is there a new reason for this error?