Android源碼環境配置之Ubuntu 14.04 LTS x64

安裝配置Java 7

安裝

Java 7: For the latest version of Android (此步如果出現錯誤,按它的提示搞:sudo apt-get -f install,再嘗試)

$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk

配置

Optionally, update the default Java version by running:

sudo update-alternatives --config java
sudo update-alternatives --config javac

安裝其他必須

Installing required packages (Ubuntu 14.04)
You will need a 64-bit version of Ubuntu. Ubuntu 14.04 is recommended.
如果出現錯誤,按提示執行
“sudo apt-get install gcc-multilib”
”sudo apt-get install g++”

sudo apt-get install bison g++-multilib git gperf libxml2-utils make zlib1g-dev:i386 zip curl

Configuring USB Access

Under GNU/Linux systems (and specifically under Ubuntu systems), regular users can’t directly access USB devices by default. The system needs to be configured to allow such access.

The recommended approach is to create a file /etc/udev/rules.d/51-android.rules (as the root user) and to copy the following lines in it. <username> must be replaced by the actual username of the user who is authorized to access the phones over USB.

# 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>"

Those new rules take effect the next time a device is plugged in. It might therefore be necessary to unplug the device and plug it back into the computer.

This is known to work on both Ubuntu Hardy Heron (8.04.x LTS) and Lucid Lynx (10.04.x LTS). Other versions of Ubuntu or other variants of GNU/Linux might require different configurations.

修改配置文件後,可以使用
sudo /etc/init.d/udev restart 來重啓usb服務

下載repo

  1. Make sure you have a bin/ directory in your home directory and that it is included in your path:

    $ mkdir ~/bin
    $ PATH=~/bin:$PATH
  2. Download the Repo tool and ensure that it is executable:

    此步在需要翻牆,參考翻牆教程

    $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    $ chmod a+x ~/bin/repo

初始化代碼庫(需要翻牆)

$ PATH=$PATH:~/bin
$ mkdir ~/android-source
$ cd ~/android-source
$ repo init -u https://android.googlesource.com/platform/manifest

When prompted, configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.

同步代碼(需要翻牆)

可選:sudo sysctl -w net.ipv4.tcp_window_scaling=0

$ repo sync

可能遇到的問題

Git版本問題

現象:

error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing ...
fatal: HTTP request failed

解決方案:

下面git版本號替換成磁盤上實際的版本號

$ sudo apt-get install build-essential fakeroot dpkg-dev
$ mkdir ~/git-openssl
$ cd ~/git-openssl
$ sudo apt-get source git
$ sudo apt-get build-dep git
$ sudo apt-get install libcurl4-openssl-dev
$ sudo dpkg-source -x git_1.7.9.5-1.dsc
$ cd git_1.7.9.5 8

Then, edit debian/control file (run the command: gksu gedit debian/control) and replace all instances of libcurl4-gnutls-dev with libcurl4-openssl-dev

sudo dpkg-buildpackage -rfakeroot -b

(if it’s failing on test, you can remove the line TEST=test from the file debian/rules)

sudo dpkg -i ../git_1.7.9.5-1_i386.deb

Doc: make clean vs make clobber
make is pretty smart, and picks up what has changed from the last build, so if you run repo sync and then build without cleaning, in most cases it should work just fine.

One exception would be after adding or updating proprietary vendor binaries. Per Google's Android documentation, Building for devices, Google does recommend:

    Cleaning up when adding proprietary binaries
    In order to make sure that the newly installed binaries are properly taken into account after being extracted, the existing output of any previous build needs to be deleted with make clobber.

make clean does the same thing as make clobber, which is removing all generated files including those in ($OUT_DIR) if defined.

需要Cleanup

如果repo sync中斷導致了untrace之類的錯誤,那麼用下面的代碼來修復再sync

$ repo sync -d
$ repo forall -c 'git reset --hard'    # Remove all working directory (and staged) changes.
$ repo forall -c 'git clean -f -d'     # Clean untracked files

代理

如果找不到可用的 google IP,那麼可以用 goagent 代理的方式。或者網絡太差

下載之後

android源碼下載後是沒有分支的

# 查看分支
$ repo branch

# 創建分支
$ repo start mywork --all

# 刪除分支
$ repo abandon mywork
  • 查看當前android版本號

    build/core/version_defaults.mk 文件中查找 PLATFORM_VERSION 即可

  • 查看repo可切換的分支 - 可以看到,默認爲 master 分支。如果看不清楚,可以用 git branch -a 來看

$ cd .repo/manifests
$ git branch -a | cut -d / -f 3
  • 查看所有分支
$ git --git-dir .repo/manifests/.git/ branch -a
  • 初始化repo客戶端到某一分支(例如 android-4.0.3_r1)
$ repo init -b android-4.0.3_r1
  • 把所有的庫切換分支
$  repo forall  -c git checkout <branch_name>
  • 刪除所有庫的某個分支
$ repo forall  -c git branch -D <branch_name>
  • 查看狀態
$ repo status

參考:

http://source.android.com/source/initializing.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章