Need help with building app onto Android device from Unity

Hi,

I have been trying to build a simple Unity scene file on an android device but with no success. I have followed all the possible tutorials and step by step installation process but no matter what I do, I just cant get rid of the following error in Unity:

Error building Player: Exception: android (invokation failed)
ERROR: unknown error
cmd:android list target -c
stdout;
stderr:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread “main”

I installed JDK1.7, JRE, Android SDK, set all path variable with necessary parameters, have dont Everything possible. I can’t think of any single step that I might have missed. I even uninstalled everything and started from scratch getting the same result. Now this is what is interesting…I am able to successfully launch an app from within the android platform (without the Unity) but somehow, I am gettign this error when I try to build the app from Unity to the device. Someone please help!! I feel like I am wasting a lot of time figuring out by myself for over 2 days and any number of googling and searching the internet for answers is just not helping.

Thanks so much!

Just to be clear, you can build the APK alone, transfer it to the device and then run it?
You cannot build the APK straight to the device. (Build and run)
Correct?

Yes, this is a bit messy right now - hopefully this will work better once the next version of unity comes out.

First of all make sure you have JDK7 installed and not only the JRE. Then make sure the JAVA_HOME has been set to point to the JDK directory. If that still doesn’t work try removing any old JDK/JRE installations that might have. If Unity fails to detect JAVA_HOME for some reason it scans the program files directories and the register for any java versions currently installed and basically grabs the first one that it can find. We have fixed this but the fix has not yet been released.

It is a probleme with jdk version, if you installed a newer version you need to add the PATH and the CLASSPATH to the environment variable and JAVA_HOME too and then downgrade anrdoidsdk to r21 because android sdk r22 is not compatible with unity 4.0