2

I am trying to build by own AOSP from google source. I follwed the steps mentioned in the Google Documents and was successfully able to build it and flash my device with the images successfully. However, I tried building it again after making some changes (basically just added some Logs to play around with it). The build errored out. I then tried to make again, it said Javac 1.6 found. Required Javac 1.7. I then followed the answers for this particular problem by using the following command:

 update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/bin/javac   1051      auto mode
* 1            /usr/lib/jvm/j2sdk1.6-oracle/bin/javac        315       manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/bin/javac   1051      manual mode

I then selected the option 0. I then tried to make again. This time it failed with the following error:

java.lang.UnsupportedClassVersionError: com/google/doclava/Doclava : Unsupported major.minor version 51.0 android build

After going through the all answers for this question(I found this asked so many times), I found it is because the complie time(higher version) and run time(lower version) JDK dont match and I should recompile it using Java 1.7. How do I do that for android build? I am also surprized why I got the error "Javac 1.6 found. Required Javac 1.7." as I successfully created the build using Java 1.6.

Ankur Bhatia
  • 996
  • 3
  • 17
  • 29

2 Answers2

8

In this case it's not the problem with javac, but with javadoc. To check its version: javadoc -J-version (yes, it's weird).

So, you have to use:

update-alternatives --config javadoc
Jacek
  • 106
  • 2
  • 8
  • Thanks Jacek for the answer. But unfortunately I dont have the system running to check this now. So really sorry wont be able to check and accept your answer at the moment. – Ankur Bhatia Sep 26 '16 at 14:10
  • Thanks, soved my problem: – Pip Oct 27 '17 at 09:10
0

This error means you're trying to load a Java "class" file that was compiled with a newer version of Java than you have installed.

For example, your .class file could have been compiled for JDK 7, and you're trying to run it with JDK 6.

So the solution is to either:

  • Upgrade your Java runtime or
  • Recompile the class if you have the source, using your local Java compiler (if you have one).

    javac FileName.java

visit this more detail: How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

Community
  • 1
  • 1
  • Thanks Harshad. But after running the command :update-alternatives --config javac, should not it run with Java 7? – Ankur Bhatia May 09 '16 at 09:59
  • @AnkurBhatia see the link in answer. –  May 09 '16 at 10:02
  • Also, the java version in my builder server is also java 1.7. Really confused. – Ankur Bhatia May 09 '16 at 10:02
  • Thanks Harshad, I saw that answer already. But the problem is in case of the Android AOSP I cant compile indivisual file. I just have the option to make. This should use the Java 1.7 now. Or am I assuming something wrong? – Ankur Bhatia May 09 '16 at 10:04