1、下载和创建
=========================官方要求说明===============================
在Ubuntu 12.04 中出现的问题:
Checking build tools versions... ************************************************************ You are attempting to build with an unsupported version of java. Your version is: java version "1.7.0_17". The correct version is: Java SE 1.6 or 1.7.
ubuntu 12.04 JDK 版本 出现问题情况解决:
下载安装OpenJDK1.6也不行,只能现在sun-jdk-1.6,下载链接:Sun JDK from here;下载后安装和设置:
$ chmod +x jdk-6u33-linux-x64.bin $ sudo ./jdk-6u33-linux-x64.bin $ sudo mv jdk1.6.0_32 /usr/lib/jvm/ $sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_33/bin/java 1 $ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_33/bin/javac 1 $ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_33/bin/javaws 1 $ sudo update-alternatives --config java $ sudo update-alternatives --config javac $ sudo update-alternatives --config javaws
安装完成后配置:
$ sudo update-alternatives --config java $ sudo update-alternatives --config javac
$ sudo apt-get install git gnupg flex bison gperf build-essential \ zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \ libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \ libgl1-mesa-dev g++-multilib mingw32 tofrodos \ python-markdown libxml2-utils xsltproc zlib1g-dev:i386 $ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
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>"
设置个人USB方法察看博客:
Put the following in your .bashrc or equivalent.
export USE_CCACHE=1
进入源码根目录执行(这个要等下面的不着下载完成android源码后):
prebuilts/misc/linux-x86/ccache/ccache -M 50G
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:(如果出错没有成功下载到repo,可能是地址或者网路问题,可以google一下国内有效的地址)
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo $ chmod a+x ~/bin/repo
1、创建空的文件夹
$ mkdir WORKING_DIRECTORY $ cd WORKING_DIRECTORY
2、Run repo init
to bring down the latest version of Repo with all its most recent bug fixes.
$ repo init -u https://android.googlesource.com/platform/manifest
使用命令察看版本分支:
git --git-dir .repo/manifests/.git/ branch -a
下载其中一个版本:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
如果网速慢可以将 "https" 改为 "http"
$ repo sync
国内网速问题解决办法:建立一个。sh执行
#!/bin/bash echo "======start repo sync======" | tee -a reposync_log.txt; repo sync while [ $? -ne 0 ]; do echo `date +%Y_%m_%d_%H:%M:%S` ": ======sync failed, re-sync again:{$?}" | tee -a reposync_log.txt; sleep 3 repo sync done
可以设定git帐号预防动态ip改变
By default, access to the Android source code is anonymous. To protect the servers against excessive usage, each IP address is associated with a quota.
When sharing an IP address with other users (e.g. when accessing the source repositories from beyond a NAT firewall), the quotas can trigger even for regular usage patterns (e.g. if many users sync new clients from the same IP address within a short period).
In that case, it is possible to use authenticated access, which then uses a separate quota for each user, regardless of the IP address.
The first step is to create a password from the password generator and to save it in ~/.netrc
according to the instructions on that page.
The second step is to force authenticated access, by using the following manifest URI:https://android.googlesource.com/a/platform/manifest
. Notice how the /a/
directory prefix triggers mandatory authentication. You can convert an existing client to use mandatory authentication with the following command:
$ repo init -u https://android.googlesource.com/a/platform/manifest
下载完成后就是编译了
1、进入源代码跟目录:
$ source build/envsetup.sh
//或者
$ . build/envsetup.sh
选择Target
$ lunch
最后:
$ make -j4 //电脑如果配置低或者还在频繁使用中 // 就使用单线程 $ make
$ export PATH=sdk_dir/tools/:$PATH
/*察看已经建立的AVD */ $ android list targets /*创建AVD avdName=自己命名 2是可用的ID*/ $ android create avd --name avdName --target 2 [--skin SkinName] /*or*/ $ android create avd -n avdName -t 2 [--skin SkinName]
安装到模拟器上
$ emulator -avd avdName -ramdisk ramdisk.img -system system.img -data userdata.img