安装Oracle JDK
第一步:区分32位还是64位操作系统
先确定你的ubuntu linux是32位还是64位的,方法很多,这里介绍一种即可。
$uname -a
第二步:卸载OpenJDK
先执行如下命令看是否安装了OpenJDK,如果已经安装,会显示java的信息。
$java -version
如果安装了OpenJDK,可用如下方法全部卸载:
$sudo apt-get purge openjdk-\*
第三步:下载Oracle JDK版本,选择"Java SE Development Kit 6u45",然后在新打开的页面点选接受Accept License Agreement
. 接受之后,选择jdk-6u45-linux-x64.bin
即可进行下载。如果你没有登录,系统会先转到登录页面,输入你在Oracle网站注册的用户名和密码即可。
第三步:安装Oracle JDK
(1) 创建java目录
$ sudo mkdir -p /usr/local/java
将你下载的jdk-6u45-linux-x64.bin拷贝至/usr/local/java目录
$ cd /usr/local/java
$ sudo cp /home/dennis/Downloads/jdk-6u45-linux-x64.bin .
(2) 解压bin文件
$ sudo chmod +x jdk-6u45-linux-x64.bin
$ sudo ./jdk-6u45-linux-x64.bin
$ sudo rm -rf jdk-6u45-linux-x64.bin
第四步:配置Orache JDK
(1) 配置JAVA_HOME和PATH环境变量
$ sudo vi /etc/profile
在该文件的末尾加上如下部分:
JAVA_HOME=/usr/local/java/jdk1.6.0_45
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
(2) 配置ubuntu的JDK和JRE的位置
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.6.0_45/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.6.0_45/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.6.0_45/bin/javaws" 1
(3) 配置Oracle为系统默认JDK/JRE
$ sudo update-alternatives --set java /usr/local/java/jdk1.6.0_45/bin/java
$ sudo update-alternatives --set javac /usr/local/java/jdk1.6.0_45/bin/javac
$ sudo update-alternatives --set javaws /usr/local/java/jdk1.6.0_45/bin/javaws
配置完成后,执行如下命令使其立即生效。
$ . /etc/profile
再次执行"java -version"显示如下:
dennis@dubuntu1404:~$ 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)
安装必备工具软件(Ubuntu 14.04 64 bit)
$ sudo apt-get install bison g++-multilib git gperf libxml2-utils
配置USB访问权限
将如下内容加入到/etc/udev/rules.d/51-android.rules
文件中
# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"
然后执行如下命令,将上述文件中的username替换为你的用户名。
$sudo sed -i 's/username/root/g' /etc/udev/rules.d/51-android.rules
下载源码
安装repo
(1) 创建目录
$ mkdir ~/bin
$ PATH=~/bin:$PATH
(2) 下载repo工具
curl http://git-repo.googlecode.com/files/repo-1.12 > ~/bin/repo
(3) 增加可执行权限
$ chmod a+x ~/bin/repo
初始化Repo客户端
(1)创建目录
$mkdir Android-4.4.2_r1
$cd Android-4.4.2_r1
(2) 初始化repo
$repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.2_r1
下载源代码
$repo sync
好了,慢慢等吧,短则数小时,长则几天几夜!我花了5个小时
源代码编译
初始化编译环境
qq@dubuntu1404:~/android-4.4.4_r1$ source build/envsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including sdk/bash_completion/adb.bash
qq@dubuntu1404:~/android-4.4.4_r1$
选择编译包
由于我的机器是nexus5 所以我这里选择10. aosp_hammerhead-userdebug
qq@dubuntu1404:~/android-4.4.4_r1$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_x86-eng
3. aosp_mips-eng
4. vbox_x86-eng
5. aosp_manta-userdebug
6. mini_mips-userdebug
7. mini_armv7a_neon-userdebug
8. mini_x86-userdebug
9. aosp_mako-userdebug
10. aosp_hammerhead-userdebug
11. aosp_tilapia-userdebug
12. aosp_deb-userdebug
13. aosp_grouper-userdebug
14. aosp_flo-userdebug
Which would you like? [aosp_arm-eng] 10
============================================
开始编译
qq@dubuntu1404:~/android-4.4.4_r1$ make -j4
j4中的数字跟你的CPU个数和核数有关
将img加载到物理机
编译完成后,连接手机(nexus5),打开USB调试,运行如下命令刷入img
$ adb reboot bootloader
// 系统将会重启
$ fastboot flashall -w
网友评论
Getting repo ...
from https://code.google.com/p/git-repo/
fatal: repository 'https://code.google.com/p/git-repo/' not found
出现这个错误,怎么破?