安装配置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
Make sure you have a bin/ directory in your home directory and that it is included in your path:
$ mkdir ~/bin $ PATH=~/bin:$PATH
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
参考: