AOSP代码下载编译及开发

本文介绍如何从官方及国内镜像站点下载Android源代码,并提供了详细的步骤说明如何使用repo工具初始化、同步代码库。此外,还介绍了编译环境的搭建、全编译过程、特定模块编译方法及真机运行指导。

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

代码下载


谷歌官方文档:http://source.android.com/source/downloading.html


资料链接


 http://blog.youkuaiyun.com/zbunix/article/details/8460422


 http://git.omapzoom.org/?p=platform/manifest.git;a=summary



谷歌开发者网站



下载repo


$curl https://storage.googleapis.com/git-repo-downloads/repo >~/bin/repo

$chmod a+x ~/bin/repo


通过repo下载代码


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

$repo sync



国内镜像下载

git.omapzoom.org网站下载

repoinit -u git://git.omapzoom.org/platform/manifest -b android-4.4.2_r2

repoinit -u git://git.omapzoom.org/platform/manifest -b android-4.4.2_r2--repo-url=http://mirrors.ustc.edu.cn/aosp/git-repo--repo-branch=stable


mirrors.ustc.edu.cn网站下载

../repoinit -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git -bandroid-7.1.0_r1--repo-url=https://aosp.tuna.tsinghua.edu.cn/git-repo--repo-branch=stable


单独下载某个仓库:gitclone http://mirrors.ustc.edu.cn/aosp/platform/frameworks/base



代码分支


谷歌官方:

http://source.android.com/source/build-numbers.html#source-code-tags-and-builds


注意:不同的分支对应的支持的硬件不同


代码编译



谷歌官方文档:http://source.android.com/source/building.html


全编译


>>准备编译环境,主要是JDK的环境变量设置

>>cd到源码根目录

>>source build/envsetup.sh或者.build/envsetup.sh

>>lunch

>>make


编译某个模块


makeLOCAL_MODULE

例如:makeframework


真机运行



为真机编译image



全编译之前,先在编译环境中安装相应的驱动

https://developers.google.com/android/nexus/drivers

安装完驱动后,进行全编译。


烧写image到手机


http://source.android.com/source/running.html#booting-into-fastboot-mode


>>解锁:进入手机的fastboot模式- >fastboot oem unlock

>>烧写:进入手机的fastboot模式- >fastboot flash system system.img


通过adb升级


adbsideload ~/tmp/os.zip

adbreboot recovery


fastboot命令



fastbootdevices

fastbootflashall

fastboot -wflashall

fastbootreboot

fastboot help

fastboot flashboot boot.img

fastboot flashsystem system.img


Recoverymode


How toboot into recovery mode on a Google Nexus device

Ifyou have a device like the Nexus 5 or Nexus7 runningstock Android then these are the steps required to boot into Recoverymode:

  1. Holddown the Power keyand select Poweroff.If the touchscreen is unresponsive then you can simply keep holdingdown the Power keyfor several seconds until the device turns off.

  2. Pressand hold the Power keyand the Volumedown key.You should see the Android mascot on his back, a bunch ofinformation about your device, andStart atthe top right of the screen.

  3. Tonavigate through the menu options you use the Volumeup and Volumedown keys.The Power keyis used to make a selection. Press Volumedowntwiceand you shuld see Recoverymode inred up at the top right, press thePower keyto select it.

  4. Thewhite Google logo will pop up followed by the Android mascot on hisback again with the words Nocommand underneath.

  5. Pressand hold the Power keyand the Volumeup keyfor around three seconds and then let go of the Volumeup key,but keep pressing Power.

  6. Youshould see the Android system recovery options pop up at the top ofthe screen. Use the Volume keysto highlight the options and the Power keyto select the one you want.


TPeamWin– TWR

https://twrp.me/



代码阅读



cddevelopment/tools/idegen

运行mm,运行完后,应该会产生out/host/linux-x86/framework/idegen.jar

cd到全部源码的根目录,运行development/tools/idegen/idegen.sh

以下错误信息应该是可以忽略:

find:`out/target/product/sailfish/root/d':权限不够

find:`out/target/product/sailfish/recovery/root/d':权限不够

最后,根目录下应该会产生文件android.ipr

androidstudio,直接打开android.ipr即可。


编译AOSP代码时,需要遵循一系列标准化的步骤,并使用特定的命令来初始化环境、选择目标设备以及执行实际的编译过程。以下是详细的说明: ### 初始化构建环境 首先,确保已经安装了所有必要的依赖项。对于Ubuntu 22.04系统,可以运行如下命令安装所需的库和工具: ```bash sudo apt-get install git gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig ``` 如果遇到缺少`libncurses5`的问题,可以创建符号链接以使用更高版本的库替代[^4]。 接下来,下载并安装`repo`工具,它用于管理多个Git仓库。可以通过以下方式获取`repo`: ```bash mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo ``` 然后,设置你的Git用户名和邮箱: ```bash git config --global user.name "Your Name" git config --global user.email "you@example.com" ``` 创建一个目录来存放AOSP源码,并进入该目录进行初始化: ```bash mkdir aosp cd aosp repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r50 ``` 这里的分支名`android-14.0.0_r50`可以根据需求更改为其他版本。 同步源代码树: ```bash repo sync ``` ### 配置编译选项 配置编译环境之前,需要加载环境变量脚本: ```bash source build/envsetup.sh ``` 之后,使用`lunch`命令选择要编译的目标产品和构建类型。例如,如果你有一台Nexus 6p真机,可以选择如下配置: ```bash lunch aosp_angler-userdebug ``` 对于模拟器或通用设备,可以选择如下的通用配置: ```bash lunch aosp_x86_64-eng ``` 其中,`-eng`表示工程版本,适合开发用途;`-userdebug`则适用于调试用户版本;而`-user`则是最终发布的用户版本。 ### 执行编译 一旦选择了合适的产品和构建类型,就可以开始编译过程。通常情况下,使用`make`命令加上-j参数指定并行任务数(建议为CPU核心数目的两倍)来进行编译: ```bash make -j$(nproc) ``` 或者,在某些较新的Android版本中可能需要使用`m`命令代替传统的`make`: ```bash m -j$(nproc) ``` 这将启动整个AOSP系统的编译流程,包括Framework、应用和其他组件。 ### 编译后的操作 成功完成编译后,可以在`out/target/product/<product_name>`目录下找到生成的镜像文件。这些镜像可以通过Fastboot工具刷入到支持的设备上,以便测试新编译的ROM。 此外,如果你想将新编译的系统部署到模拟器中,可以直接运行: ```bash emulator ``` 这个命令会启动带有最新编译结果的Android Emulator。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值