编译源码时遇到的You are attempting to build with an unsupported JDK问题


在编译android低版本代码时,make failed了,提示如下:

************************************************************
You are attempting to build with an unsupported JDK.
You use OpenJDK but only Sun/Oracle JDK is supported.
Please follow the machine setup instructions at
 https://source.android.com/source/download.html
************************************************************
build/core/main.mk:155: *** stop.  Stop.

说明编译需要的jdk版本和当前环境下的jdk版本不兼容,首先查看当前java环境:

$ xxx@ubuntu:$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

之所以出现这个问题,是因为我的jdk为openjdk1.8,在android5.0以前,编译源码使用oracleJDK,从5.0之后,开始使用openJDK,相关版本和对应JDK如下:

Android 7.0 (Nougat) - Android 8.0 (O):Ubuntu - OpenJDK 8;Mac OS - jdk 8u45 或更高版本
Android 5.x (Lollipop) - Android 6.0 (Marshmallow):Ubuntu - OpenJDK 7;Mac OS - jdk-7u71-macosx-x64.dmg
Android 2.3.x (Gingerbread) - Android 4.4.x (KitKat):Ubuntu - Java JDK 6;Mac OS - Java JDK 6
Android 1.5 (Cupcake) - Android 2.2.x (Froyo):Ubuntu - Java JDK 5

因此,如果要编译4.4的代码,应该使用OracleJDK6.所以,先安装OracleJDK1.6,安装步骤如下:
1,首选下载jdk1.6:
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html
2.jdk1.6没有提供tar.gz包,而是.bin文件,因此修改权限为可执行文件:
chmod +x jdk-6u45-linux-x64.bin
3.运行该文件:
./jdk-6u45-linux-x64.bin
运行之后,会生成一个jdk1.6.0_45文件夹
4.移动该文件夹到/usr/local/java中:
sudo mv jdk1.6.0_45/ /usr/local/java
5.配置环境变量:
sudo gedit ~/.bashrc
使用gedit打开.bashrc文件,并添加如下语句:

export JAVA_HOME=/usr/local/java/jdk1.6.0_45
export JRE_HOME=${JAVA_HOME}/jre 
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib 
export PATH=${JAVA_HOME}/bin:$PATH

这时整个java1.6环境就配好了,接下来还需要进行几步以便和多个java环境间进行切换。
6.用 update-alternatives 工具来添加 Java 可选配置项:

sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.6.0_45/bin/java 700 sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.6.0_45/bin/javac 700

7.将当前Java环境切换到java6:
sudo update-alternatives --config java

There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/local/java/jdk1.6.0_45/bin/java             700       manual mode
  3            /usr/local/java/jdk1.8.0_161/jre/bin/java        700       manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/local/java/jdk1.6.0_45/bin/java to provide /usr/bin/java (java) in manual mode

如果出现如上内容,说明配置了三个java环境,带×号的环境表示当前所处的java环境,选择对应数字切换后,再使用java -version查看当前java环境:

xxx@ubuntu:$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
xxx@ubuntu:$ 

说明切换成功
对于其他版本的jdk安装,可能从官网下载的为tar.gz形式的,不过步骤和安装jdk1.6类似。只需要解压tar包就行了,这里以jdk1.8为例,解压命令如下:
tar zxvf jdk-8u161-linux-x64.tar.gz jdk1.8.0_161

智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告