搭建android源代码编译环境

1.配置JDK6

(1)root身份编辑sources.list文件:sudo gedit  /etc/apt/sources.list

(2)在sources.list文件末尾添加如下源:deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse

(3)保存sources.list后在终端进行更新操作:sudo apt-get update

(4)执行如下命令安装jdk6:apt-get install sun-java6-jdk。

或者如下:

$ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

2.安装工具包

  sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev  lib32readline-gplv2-dev lib32z1-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc

3.配置USB访问

(1)create a file/etc/udev/rules.d/51-android.rules

(2)以下内容复制,保存。OWNER="lbj"改为自己的用户名。

# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="lbj"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="lbj"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="lbj"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="lbj"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="lbj"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="lbj"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="lbj"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="lbj"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="lbj"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="lbj"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="lbj"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="lbj"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="lbj"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="lbj"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="lbj"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="lbj"


4.配置ccache

①安装ccache
  $sudo apt-get install ccache
②查看安装路径
 $which ccache
/usr/bin/ccache
③$sudo mkdir ~/.bin
④ $ cd ~/.bin/
   $ sudo ln -s /usr/bin/ccache gcc
   $ sudo ln -s /usr/bin/ccache g++
   $ sudo ln -s /usr/bin/ccache arm-linux-gcc
   $ sudo ln -s /usr/bin/ccache arm-linux-g++
⑤设置PATH,将~/.bin/放在 arm-linux-gcc等的PATH的前面。
原:PATH=/usr/local/arm-linux_pre4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
现:PATH= /home/<user>/.bin:/usr/local/arm-linux_pre4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 gedit ~/.bashrc 添加 export PATH="/home/<user>/.bin:$PATH" ,然后重启即可
⑥$ which arm-linux-gcc
/home/<user>/.bin/arm-linux-gcc 确认

5.配置repo
(1) $ mkdir ~/bin   PATH 添加 /home/lbj/bin
(2)root@ubun:/home/lbj/bin# curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22889  100 22889    0     0  55965      0 --:--:-- --:--:-- --:--:-- 88374
(3)sudo chmod a+x ~/bin/repo
  (4)产生用户名和密码
1. 浏览器登录https://android.googlesource.com/new-password,并用gmail帐号登录;

2. 点击网页上的“允许访问”,得到类似:

    machine android.googlesource.com login git-<userName>.gmail.com password <password>  
    machine android-review.googlesource.com login git-<userName>.gmail.com password <password>  

的信息。

3. 把上面那段信息(<userName>和<password>用自己得到的真实信息)追加到~/.netrc文件结尾;(root用户下)

4. 下载地址的URI更改为https://android.googlesource.com/a/platform/manifest(中间加上了“/a”)。

(5)root@ubun:/home/lbj/workdir# repo init -u https://android.googlesource.com/a/platform/manifest
(6)root用户下
$ sudo sysctl -w net.ipv4.tcp_window_scaling=0
$ repo sync -j8








 

你可能感兴趣的:(搭建android源代码编译环境)