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:

安装完成后配置:

android 源码下载、编译和测试
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
android 源码下载、编译和测试

Installing required packages (Ubuntu 12.04)

android 源码下载、编译和测试
$ 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
android 源码下载、编译和测试

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.

android 源码下载、编译和测试
# 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.

android 源码下载、编译和测试
export USE_CCACHE=1
android 源码下载、编译和测试

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

android 源码下载、编译和测试
prebuilts/misc/linux-x86/ccache/ccache -M 50G
android 源码下载、编译和测试

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:

android 源码下载、编译和测试
$ mkdir ~/bin
$ PATH=~/bin:$PATH
android 源码下载、编译和测试

2、Download the Repo tool and ensure that it is executable:(如果出错没有成功下载到repo,可能是地址或者网路问题,可以google一下国内有效的地址)

android 源码下载、编译和测试
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
android 源码下载、编译和测试

Initializing a Repo client

1、创建空的文件夹

android 源码下载、编译和测试
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
android 源码下载、编译和测试

2、Run repo init to bring down the latest version of Repo with all its most recent bug fixes.

android 源码下载、编译和测试
$ repo init -u https://android.googlesource.com/platform/manifest
android 源码下载、编译和测试

使用命令察看版本分支:

android 源码下载、编译和测试
git --git-dir .repo/manifests/.git/ branch -a
android 源码下载、编译和测试

下载其中一个版本:

android 源码下载、编译和测试
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
android 源码下载、编译和测试
如果网速慢可以将 "https" 改为 "http"

Downloading the Android Source Tree

$ repo sync
国内网速问题解决办法:建立一个。sh执行
android 源码下载、编译和测试
#!/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
android 源码下载、编译和测试

可以设定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:

android 源码下载、编译和测试
$ repo init -u https://android.googlesource.com/a/platform/manifest
android 源码下载、编译和测试

下载完成后就是编译了

1、进入源代码跟目录:

android 源码下载、编译和测试
$ source build/envsetup.sh

//或者
$ . build/envsetup.sh
android 源码下载、编译和测试
选择Target
$ lunch

最后:

android 源码下载、编译和测试
$ make -j4
//电脑如果配置低或者还在频繁使用中
// 就使用单线程
$ make
android 源码下载、编译和测试

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

android 源码下载、编译和测试
$ export PATH=sdk_dir/tools/:$PATH
android 源码下载、编译和测试

建立AVD

android 源码下载、编译和测试
/*察看已经建立的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] 
android 源码下载、编译和测试

安装到模拟器上

android 源码下载、编译和测试
$ emulator -avd avdName -ramdisk ramdisk.img -system system.img -data userdata.img
android 源码下载、编译和测试

 

android 源码下载、编译和测试,布布扣,bubuko.com

android 源码下载、编译和测试

上一篇:< IOS > IOS适配,简单的分析解决一下


下一篇:[Android界面3]屏幕比例,像素,自适应