android 源码下载、编译和测试


1、下载和创建

=========================官方要求说明===============================

    • A Linux or Mac system. It is also possible to build Android in a virtual machine on unsupported systems such as Windows. If you are running Linux in a virtual machine, you need at least 16GB of RAM/swap and 30GB or more of disk space in order to build the Android tree.
    • A 64-bit environment is required for Gingerbread (2.3.x) and newer versions, including the master branch. You can compile older versions on 32-bit systems.
    • 30GB of free disk space to complete a single build and up to 100GB or more for a full set of builds. The source download is approximately 8.5GB in size.
    • Python 2.6 -- 2.7, which you can download from python.org.
    • GNU Make 3.81 -- 3.82, which you can download from gnu.org,
    • JDK 7 to build the latest version of Android in the Android Open Source Project (AOSP); JDK 6 to build Gingerbread through KitKat; JDK 5 for Cupcake through Froyo. See Initializing a Build Environment for installation instructions by operating system.
    • Git 1.7 or newer. You can find it at git-scm.com.
    • Java 6: for Gingerbread through KitKat (注意使用sun-java-6
      Java 5: for Cupcake through Froyo
    • To develop older versions of Android, download and install the corresponding version of the Java JDK:

在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

Installing required packages (Ubuntu 12.04)

$ 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

Configuring USB 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>"
View Code

设置个人USB方法察看博客:

Configuring USB access under Ubuntu

Setting up ccache

Put the following in your .bashrc or equivalent.

export USE_CCACHE=1

进入源码根目录执行(这个要等下面的不着下载完成android源码后):

prebuilts/misc/linux-x86/ccache/ccache -M 50G

Downloading the Source

Installing 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:(如果出错没有成功下载到repo,可能是地址或者网路问题,可以google一下国内有效的地址)

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

Initializing a Repo client

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"

Downloading the Android Source Tree

$ 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改变

Using Authentication


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

编译成功后运行:(设置android SDK目录下的tools的环境变量)

$ export PATH=sdk_dir/tools/:$PATH

建立AVD

/*察看已经建立的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

 

posted @ 2014-04-21 20:31  blackBox  阅读(952)  评论(0编辑  收藏  举报