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 frompython.org.
    • GNU Make 3.81 -- 3.82, which you can download fromgnu.org,
    • JDK 7 to build the latest version of Android in theAndroid Open Source Project (AOSP); JDK 6 to build Gingerbread through KitKat; JDK 5 for Cupcake through Froyo. SeeInitializing a Build Environmentfor installation instructions by operating system.
    • Git 1.7 or newer. You can find it atgit-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 theJava JDK:

在Ubuntu 12.04 中出现的问题:

Checking build tools versions...************************************************************You are attempting to build with an unsupported versionof 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 fromhere;下载后安装和设置:

$ 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、Runrepo initto 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/bashecho "======start repo sync======" | tee -a reposync_log.txt;repo syncwhile [ $? -ne 0 ]; do    echo `date +%Y_%m_%d_%H:%M:%S` ": ======sync failed, re-sync again:{$?}" | tee -a reposync_log.txt;    sleep 3    repo syncdone

可以设定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 fromthe password generatorand to save it in~/.netrcaccording 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

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. Android版本28使用http请求报错not permitted by network securi
  6. [Android]安装使用SDK Manager更新时出现问题
  7. Android——编译release版签名系统
  8. Android(安卓)Resource介绍和使用(二)
  9. Android(安卓)命令行手动编译打包详解

随机推荐

  1. RocketMQ-Spring 毕业两周年,为什么能成为
  2. 春节期间,课程6折特惠
  3. 刷票小程序案例原理剖析(python和java)
  4. 大公司面试必备这些知识点
  5. python单下划线开头和双下划线开头的方法
  6. 基础数论总结
  7. 华三交换机融合AC升级总结
  8. Spring Boot Admin 集成诊断利器 Arthas
  9. python可视化文本分析(2)—snownlp+jieba
  10. python可视化文本分析-分析Q群聊天记录(