Android编译环境搭建

本文档详细介绍了如何搭建Android编译环境,包括所需的基础工具安装、官方源码下载、初始化环境、选择编译目标等步骤,并提供了Android源码目录结构的说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android编译环境搭建
  • A Linux or Mac system.  The Android build is routinely tested in house on recent versions of Ubuntu LTS (10.04), but most distributions should have the required build tools available. 
  • 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.
  • Python 2.6 -- 2.7
  • GNU Make 3.81 -- 3.82
  • JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older.
  • Git 1.7 or newer
必要的工具
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
  libxml2-utils xsltproc

Android官方源码下载
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:

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

Initializing a Repo client

  1. Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:

    $ 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. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.

    $ repo init -u https://android.googlesource.com/platform/manifest

    To check out a branch other than "master", specify it with -b:

    $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1

Downloading the Android Source Tree

To pull down the Android source tree to your working directory from the repositories as specified in the default manifest, run

$ repo sync

Android源码其他获取方式
1、解决方案提供商
2、Soc开源社区www.linaro.org

Android源码目录结构
abiapplication binary interface
bionicC Runtime:libc libm libdl dynamic linker Bionic含义为仿生,这里面是一些基础的库的源代码
bootloader/legacyBootloader reference code启动引导相关代码
buildBuild System,build目录中存放的是编译系统mk文件,编译规则和generic产品基础配置文件
ctsAndroid兼容性测试套件标准
dalvikDalvik Virtual Machine
developmentHigh-level development and debugging tools,程序开发所需要的模板和工具,如AVD,实例代码
device设备相关代码
frameworkCore Android app framework libraries 核心框架--java及C++语言,是Android应用程序的框架
hardware主要是硬件适配层HAL代码
ndkndk(Android NativeDevelopment Kit)相关代码
out编译完成后的输出目录
prebuiltBinaries to support Linux and Mac OS builds,x86和arm架构下预编译的一些资源
packageAndroid的各种系统级应用程序
sdkSDK 工具源码及qemu相关源码
systemAndroid根文件系统相关源码,如:init、adb、toolbox及一些库
docs介绍开源的相关文档
externalAndroid使用的一些开源的模块代码
libcore核心库相关

Android源码编译

Initialize


Initialize the environment with the envsetup.sh script. Note that replacing "source" with a single dot saves a few characters, and the short form is more commonly used in documentation.

$ source build/envsetup.sh

or

$ . build/envsetup.sh

Choose a Target


Choose which target to build with lunch. The exact configuration can be passed as an argument, e.g.

$ lunch aosp_arm-eng

The example above refers to a complete build for the emulator, with all debugging enabled.

If run with no arguments lunch will prompt you to choose a target from the menu.

All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename referring to the particular feature combination. Here's a partial list:

Build name Device Notes
aosp_arm ARM emulator AOSP, fully configured with all languages, apps, input methods
aosp_maguro maguro AOSP, running on Galaxy Nexus GSM/HSPA+ ("maguro")
aosp_panda panda AOSP, running on PandaBoard ("panda")

and the BUILDTYPE is one of the following:

Buildtype Use
user limited access; suited for production
userdebug like "user" but with root access and debuggability; preferred for debugging
eng development configuration with additional debugging tools

For more information about building for and running on actual hardware, see Building for Devices.

Build the Code


Build everything with make. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16 and make -j32.

$ make -j4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值