Android 工程编译 Unsupported major.minor version 51.0 错误解决方法(JDK版本问题)

在编译高低版本Android工程时使用如下命令切换java版本似乎并不彻底

$ sudo update-alternatives –config java

$ sudo update-alternatives –config javac

 

会出现如下错误:

java.lang.UnsupportedClassVersionError: com/google/doclava/Doclava : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.sun.tools.javadoc.DocletInvoker.(DocletInvoker.java:74)
    at com.sun.tools.javadoc.Start.setDocletInvoker(Start.java:380)
    at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:179)
    at com.sun.tools.javadoc.Start.begin(Start.java:128)
    at com.sun.tools.javadoc.Main.execute(Main.java:41)
    at com.sun.tools.javadoc.Main.main(Main.java:31)
Copying: out/target/common/obj/APPS/Telecom_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/APPS/TelephonyProvider_intermediates/classes-jarjar.jar
javadoc: error - fatal error

 

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/cts/tradefed/command/CtsConsole : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.android.cts.tradefed.command.CtsConsole.  Program will exit.

 

解决方法:

$ update-java-alternatives –list

    java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64

    java-6-oracle 1073 /usr/lib/jvm/java-6-oracle

$ sudo update-java-alternatives –set java-1.7.0-openjdk-amd64

 

Reference:

https://groups.google.com/forum/#!topic/android-building/fwieDLe

你可能感兴趣的:(Android 工程编译 Unsupported major.minor version 51.0 错误解决方法(JDK版本问题))