Serge Ungar
Serge Ungar

Reputation: 31

building android error java version

I'm newbie in building android OS.

I use Ubuntu 14.04 LTS and the JDK 8.

The envsetup.sh gives :

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=6.0.1
TARGET_PRODUCT=aosp_arm
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-85-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=MASTER
OUT_DIR=out
============================================

And I try to compile with make -J4

I get the foolowing error :

============================================
You asked for an OpenJDK 7 build but your version is
java version "1.8.0_92" Java(TM) SE Runtime Environment (build 1.8.0_92-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode).
************************************************************
build/core/main.mk:220: *** stop.
make: *** [out/build-aosp_arm.ninja] Erreur 1
============================================

So I change the JDK to version 7 but I get the same error but inverted :

============================================
You asked for an OpenJDK 8 build but your version is
java version "1.7.x" Java(TM) SE Runtime Environment (build 1.7.x) Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode).
************************************************************

So what is the pb ?

How can I solve it ?

Thank for your help

Upvotes: 3

Views: 5004

Answers (2)

Alexandre Schmidt
Alexandre Schmidt

Reputation: 618

I know this thread is old, but I'm working with Android 6 today, so I went through the same issue... For me, this helped:

If you want to force using Java 8, you can use this:

export EXPERIMENTAL_USE_JAVA8=1

Then make again:

m

But, as the name says, it is experimental, thus not recommended.

For me (Ubuntu 18.04.1), I had to download Java 7 (https://jdk.java.net/java-se-ri/7) and:

cd /usr/lib/jvm/
sudo tar zxf /tmp/openjdk-7u75-b13-linux-x64-18_dec_2014.tar.gz
sudo chown root:root java-se-7u75-ri -R

The above will create /usr/lib/jvm/java-se-7u75-ri and set it as owned by user and group root.

Now add it to PATH, as stated in https://source.android.com/setup/build/building#wrong-java-version:

[...] Prepend the correct JDK to the beginning of your path or remove the problematic JDK.

export PATH="/usr/lib/jvm/java-se-7u75-ri/bin:$PATH"

I also had to patch build/core/main.mk:

diff --git a/core/main.mk b/core/main.mk
index a6f829ab6..97690add0 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -153,7 +153,7 @@ javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.8[\. "$$]')
 else # default
 required_version := "1.7.x"
 required_javac_version := "1.7"
-java_version := $(shell echo '$(java_version_str)' | grep '^java .*[ "]1\.7[\. "$$]')
+java_version := $(shell echo '$(java_version_str)' | grep '^openjdk .*[ "]1\.7[\. "$$]')
 javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.7[\. "$$]')
 endif # if EXPERIMENTAL_USE_JAVA8

Note it was grep'ing for '^java .*[ "]1\.7[\. "$$]' and I changed it to '^openjdk .*[ "]1\.7[\. "$$]'.

After that, I issued m to make again.

Hope this can help someone else out there. :)

Upvotes: 4

Punk Unity
Punk Unity

Reputation: 11

You asked for an OpenJDK 8 build but your version is java version "1.7.x" Java(TM) SE Runtime Environment (build 1.7.x) Java HotSpot(TM)

You need Java 7 like the error message states. Download OpenJdk 7, and install it. Then you need to

sudo update-alternatives --config java

sudo update-alternatives --config javac

On both of those choose 1.7 or 7 for the version. Google and XDA has this covered already... Java-8 will be used for Android N going forward, but for KK and MM, you need 7.

Upvotes: 1

Related Questions