一,ubuntu14.04 安装 open-jdk-1.8
在 ubuntu 下,把jdk 解压到 /usr/lib/jvm/ 目录下,配置环境变量,就ok.
下面是我已经安装的jdk
crg@crg-pc:/usr/lib/jvm$ ll
total 60
drwxr-xr-x 7 root root 4096 3月 3 15:02 ./
drwxr-xr-x 180 root root 28672 3月 3 15:02 ../
lrwxrwxrwx 1 root root 20 4月 25 2016 java-1.7.0-openjdk-amd64 -> java-7-openjdk-amd64/
-rw-r--r-- 1 root root 2439 2月 8 09:10 .java-1.7.0-openjdk-amd64.jinfo
drwxr-xr-x 7 root root 4096 3月 3 14:57 java-7-openjdk-amd64/
drwxr-xr-x 8 root root 4096 3月 3 15:02 java-8-oracle/
-rw-r--r-- 1 root root 2643 3月 3 15:02 .java-8-oracle.jinfo
drwxr-xr-x 8 crg crg 4096 3月 27 2013 jdk1.6.0_45/
drwxr-xr-x 8 crg crg 4096 4月 11 2015 jdk1.7.0_79/
drwxr-xr-x 8 crg crg 4096 4月 1 2016 jdk1.8.0_92/
现在安装 JDK1.8:
终端命令行:
添加软件源
sudo add-apt-repository ppa:openjdk-r/ppa
更新源
sudo apt-get update
安装 openjdk-8-jdk
sudo apt-get install openjdk-8-jdk
我安装后的文件目录如下:
lrwxrwxrwx 1 root root 20 4月 25 2016 java-1.7.0-openjdk-amd64 -> java-7-openjdk-amd64/
-rw-r--r-- 1 root root 2439 2月 8 09:10 .java-1.7.0-openjdk-amd64.jinfo
lrwxrwxrwx 1 root root 20 11月 5 21:40 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64/
-rw-r--r-- 1 root root 2600 11月 5 21:40 .java-1.8.0-openjdk-amd64.jinfo
drwxr-xr-x 7 root root 4096 3月 3 14:57 java-7-openjdk-amd64/
drwxr-xr-x 7 root root 4096 3月 3 15:24 java-8-openjdk-amd64/
drwxr-xr-x 8 root root 4096 3月 3 15:02 java-8-oracle/
-rw-r--r-- 1 root root 2643 3月 3 15:02 .java-8-oracle.jinfo
drwxr-xr-x 8 crg crg 4096 3月 27 2013 jdk1.6.0_45/
drwxr-xr-x 8 crg crg 4096 4月 11 2015 jdk1.7.0_79/
drwxr-xr-x 8 crg crg 4096 4月 1 2016 jdk1.8.0_92/
目前我安装了 6个版本的 jdk:
使用那个版本的jdk,就在环境变量配置那个版本,管理方便
我在 ~/.bashrc 里面配置:
crg@crg-pc:~$ vim .bashrc
# export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export PATH=${CLASSPATH}:$PATH
export ANDROID_HOME=/home/crg/develop/Sdk
export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH
export GRADLE_HOME=/home/crg/develop/package/android-studio/gradle/gradle-2.10
export PATH=$GRADLE_HOME/bin:$PATH
# export REPO_HOME=/usr/local
export REPO_HOME=/home/crg
export PATH=$REPO_HOME/bin:$PATH
在 .bashrc 文件结尾,配置的我电脑的环境变量,管理方便,修改完成,执行
source .bashrc
修改的环境变量生效,验证如下:
crg@crg-pc:~$ java -version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-3~14.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14,mixed mode)
crg@crg-pc:~$ javac -version
javac 1.8.0_111
crg@crg-pc:~$
寻找某个命令的安装目录,执行如下:
crg@crg-pc:~$ which java
得到java 安装目录:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java
二,编译 android 源码
启动编译环境
crg@crg-pc:~/neolink_source/nougat_7.1_api_25$ . build/envsetup.sh
lunch 选择一个分支编译
crg@crg-pc:~/neolink_source/nougat_7.1_api_25$ lunch
You're building on Linux Lunch menu... pick a combo: 1. aosp_arm-eng 2. aosp_arm64-eng 3. aosp_mips-eng 4. aosp_mips64-eng 5. aosp_x86-eng 6. aosp_x86_64-eng 7. full_fugu-userdebug 8. aosp_fugu-userdebug 9. mini_emulator_arm64-userdebug 10. m_e_arm-userdebug 11. m_e_mips64-eng 12. m_e_mips-userdebug 13. mini_emulator_x86_64-userdebug 14. mini_emulator_x86-userdebug 15. aosp_dragon-userdebug 16. aosp_dragon-eng 17. aosp_marlin-userdebug 18. aosp_sailfish-userdebug 19. aosp_flounder-userdebug 20. aosp_angler-userdebug 21. aosp_bullhead-userdebug 22. hikey-userdebug 23. aosp_shamu-userdebug Which would you like? [aosp_arm-eng] 1
执行 make -j4 开始编译
出现如下,编译完成
#### make completed successfully (01:45:59 (hh:mm:ss)) ####
编译的 img 文件位置:
out/target/product/generic
884K ./recovery
4.0K ./prevIoUs_build_config.mk
22M ./userdata.img
11M ./data
72K ./installed-files.txt
1.8G ./system.img
4.0K ./cache
1.3M ./ramdisk.img
4.0K ./android-info.txt
4.0K ./build_fingerprint.txt
5.1M ./cache.img
15G ./obj
473M ./system
149M ./gen
2.4M ./root
3.0G ./symbols
72K ./clean_steps.mk
74M ./dex_bootjars
920K ./module-info.json
20G .
三,编译 SDK
crg@crg-pc:~/neolink_source/nougat_7.1_api_25$ lunch sdk-eng
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.1
TARGET_PRODUCT=sdk
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-4.2.0-42-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=NOF26W
OUT_DIR=out
============================================
crg@crg-pc:~/neolink_source/nougat_7.1_api_25$ make sdk -j4
四,编译过程出现的异常情况
编译源码和SDK 都可能出现 out of memory 编译中断:
解决办法
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server
再执行 make 编译
我笔记本 6G 内存,编译源码和SDK都出现了此问题
五,Android 新一代编译 toolchain Jack & Jill 简介
android 7.1 源码编译器用 新的 JACK 代替以前的 javac/dx/ProGuard/jarjar toolchain
具体参考链接
Android 新一代编译 toolchain Jack & Jill 简介: