Skip to Content
嵌入式 Android
book

嵌入式 Android

by Karim Yaghmour
July 2025
Intermediate to advanced
412 pages
6h 9m
Chinese
O'Reilly Media, Inc.
Content preview from 嵌入式 Android

第 3 章.AOSP 快速启动

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

现在你已经对基础知识有了扎实的了解,让我们开始动手使用 Android 开源项目(AOSP)吧。首先,我们将介绍如何从http://android.googlesource.com/ 获取 AOSP 发行版在实际构建和运行 AOSP 之前,我们将花一些时间探索 AOSP 的内容,并解释源代码如何反映我们在前一章中看到的内容。最后,我们将在本章结尾介绍adb和模拟器的使用,这是进行任何平台工作时都非常重要的两个工具。

最重要的是,本章将充满乐趣。AOSP 是一款令人兴奋的软件,拥有大量创新。好吧,我承认它并不都是美好的,有些部分确实有粗糙的边缘。不过,其他部分还是纯粹的天才。最令人惊奇的显然是,我们都可以下载、修改它,并在此基础上推出自己的定制产品。所以,卷起袖子,让我们开始吧。

开发主机设置

正如我们在 "开发设置与工具"一文中所讨论的,要在 AOSP 上运行,你需要一个基于 Ubuntu 的桌面。尽管其他系统也能运行,但谷歌文档中只支持 Ubuntu。我建议你回头重读一下那一部分,看看 AOSP 工作所需的基本主机设置。此外,我还建议你看看谷歌网站http://source.android.com上的 "初始化构建环境"(Initializing a Build Environment)部分,了解如何为构建 Android 源代码设置主机的最新信息。该页面还包括配置udev,以确保正确设置权限,让你可以访问连接到主机的 Android 设备。

获取 AOSP

如前所述,官方 AOSP 可在 http://android.googlesource.com 获取该网站提供图 3-1 所示的 Gitweb 界面(git的 Web 界面)。 访问该网站时,你会看到相当多的 Git 仓库可供调用。不用说,手动拉取每一个都会相当乏味;这些仓库有 100 多个。而且,事实上,把它们都拉出来也没什么用,因为我们只需要这些项目的一个子集。拉取 AOSP 的正确方法是使用repo工具,该工具可在同一位置获取。首先,你需要获取repo本身:

$ sudo apt-get install curl
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
The Android Git repositories web frontend
图 3-1.Android Git 仓库网页前端

警告

在 Ubuntu 下,如果 ~/bin 已经存在,登录时会自动添加到路径中。因此,如果你的主目录中没有bin/目录,请先创建一个,然后注销并重新登录,使其成为路径的一部分。 否则,即使按我刚才演示的方法获取了repo,shell 也无法找到它。

如果在 Ubuntu 或其他发行版中无法正常工作,请手动在~/.profile中添加PATH=$PATH:~/bin ,然后注销并重新登录。

注意

你不必把repo放在~/bin 中,但它必须在你的路径中。因此,无论你把它放在哪里,只需确保它在命令行文件系统的所有位置都可用。

尽管只是一个 shell 脚本,repo其实是个相当复杂的工具。 它可以同时从多个Git仓库中提取数据来创建 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Practical Android Projects

Practical Android Projects

Lucas Jordan, Pieter Greyling
GPU Pro 5

GPU Pro 5

Wolfgang Engel

Publisher Resources

ISBN: 9798341663206