平台架构
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 是一个基于 Linux 的开源软件堆栈,针对多种不同设备类型打造。图 1 显示了 Android 平台的主要组件。
图 1. Android 软件堆栈。
Linux 内核
Android 平台的基础是 Linux 内核。例如,Android 运行时 (ART) 依赖 Linux 内核来实现底层功能,例如线程处理和低级内存管理。
使用 Linux 内核可让 Android 利用关键安全功能,并让设备制造商能够为知名内核开发硬件驱动程序。
硬件抽象层 (HAL)
硬件抽象层 (HAL) 提供了用于向较高级别的 Java API 框架公开设备硬件功能的标准接口。HAL 由多个库模块组成,每个模块都为特定类型的硬件组件(例如相机或蓝牙模块)实现一个接口。当框架 API 发出调用以访问设备硬件时,Android 系统将为该硬件组件加载库模块。
Android 运行时
对于搭载 Android 5.0(API 级别 21)或更高版本的设备,每个应用都在其自己的进程中运行,并且有其自己的 Android 运行时 (ART) 实例。ART 编写为通过执行 Dalvik 可执行文件格式 (DEX) 文件,在低内存设备上运行多个虚拟机。DEX 文件是一种专为 Android 设计的字节码格式,针对最小的内存占用量进行了优化。构建工具(如 d8
)可将 Java 源代码编译成 DEX 字节码,此类字节码可在 Android 平台上运行。
ART 的部分主要功能包括:
- 预先 (AOT) 和即时 (JIT) 编译
- 优化的垃圾回收 (GC)
- 在 Android 9(API 级别 28)及更高版本中,可将应用软件包的 DEX 文件转换为更紧凑的机器代码
- 可提供更好的调试支持,包括专用采样剖析器、详细的诊断异常和崩溃报告,以及设置观察点以监控特定字段的能力
在 Android 版本 5.0(API 级别 21)之前,Dalvik 是 Android 运行时。如果您的应用在 ART 上运行良好,那么它也可以在 Dalvik 上运行,但反过来不一定。
Android 还包含一套核心运行时库,可提供 Java API 框架所使用的 Java 编程语言中的大部分功能,包括一些 Java 8 语言功能。
原生 C/C++ 库
许多核心 Android 系统组件和服务(如 ART 和 HAL)都是从需要用 C 和 C++ 编写的原生库的原生代码构建的。Android 平台提供 Java 框架 API,用于向应用提供其中一些原生库的功能。例如,您可以通过 Android 框架的 Java OpenGL API 访问 OpenGL ES,以支持在应用中绘制和操控 2D 和 3D 图形。
如果开发的是需要 C 或 C++ 代码的应用,可以使用 Android NDK 直接从原生代码访问某些原生平台库。
Java API 框架
您可通过以 Java 语言编写的 API 使用 Android 操作系统的整个功能集。这些 API 是创建 Android 应用所需的构建块的基础,可简化核心、模块系统组件和服务的重复使用,包括以下组件和服务:
开发者可以完全访问 Android 系统应用使用的相同框架 API。
系统应用
Android 随附一套用于电子邮件、短信、日历、互联网浏览和通讯录等的核心应用。平台随附的应用与用户可以选择安装的应用一样,没有特殊状态。因此,第三方应用可以成为用户的默认网络浏览器、短信应用甚至默认键盘。但有一些例外情况,例如系统的“设置”应用。
系统应用既可用作用户体验应用,又能提供开发者可从自己的应用访问的关键功能。例如,如果您希望应用发送短信,则无需自行构建该功能。您可以改为调用已安装的短信应用,将消息发送给您指定的接收者。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Platform architecture\n\nAndroid is an open source, Linux-based software stack created for a wide\narray of devices and form factors. Figure 1 shows the major\ncomponents of the Android platform.\n\n\n**Figure 1.** The Android software stack.\n\nLinux kernel\n------------\n\n\nThe foundation of the Android platform is the Linux kernel. For example,\n[the Android Runtime (ART)](#art) relies on the Linux kernel for\nunderlying functionalities such as threading and low-level memory management.\n\n\nUsing a Linux kernel lets Android take advantage of [key\nsecurity features](https://source.android.com/security/overview/kernel-security.html) and lets device manufacturers develop hardware\ndrivers for a well-known kernel.\n\nHardware abstraction layer (HAL)\n--------------------------------\n\n\nThe [hardware abstraction layer (HAL)](https://source.android.com/devices/architecture/hal) provides standard interfaces that expose\ndevice hardware capabilities to the higher-level [Java API framework](#api-framework). The HAL consists of multiple library\nmodules, each of which implements an interface for a specific type of hardware\ncomponent, such as the [camera](https://source.android.com/devices/camera/index.html) or [Bluetooth](https://source.android.com/devices/bluetooth.html) module.\nWhen a framework API makes a call to access device hardware, the Android\nsystem loads the library module for that hardware component.\n\nAndroid runtime\n---------------\n\n\nFor devices running Android version 5.0 (API level 21) or higher, each app\nruns in its own process and with its own instance of the [Android Runtime\n(ART)](https://source.android.com/devices/tech/dalvik/index.html). ART is written to run multiple virtual machines on low-memory\ndevices by executing Dalvik Executable\nformat (DEX) files, a bytecode format designed specifically for\nAndroid that's optimized for a minimal memory footprint. Build tools, such\nas [`d8`](/studio/command-line/d8), compile\nJava sources into DEX bytecode, which can run on the Android platform.\n\n\nSome of the major features of ART include the following:\n\n- Ahead-of-time (AOT) and just-in-time (JIT) compilation\n- Optimized garbage collection (GC)\n- On Android 9 (API level 28) and higher, [conversion](/about/versions/pie/android-9.0#art-aot-dex) of an app package's DEX files to more compact machine code\n- Better debugging support, including a dedicated sampling profiler, detailed diagnostic exceptions and crash reporting, and the ability to set watchpoints to monitor specific fields\n\n\nPrior to Android version 5.0 (API level 21), Dalvik was the Android runtime.\nIf your app runs well on ART, then it can work on Dalvik as well, but\n[the reverse might not be\ntrue](/guide/practices/verifying-apps-art).\n\n\nAndroid also includes a set of core runtime libraries that provide most of\nthe functionality of the Java programming language, including some [Java 8 language features](/guide/platform/j8-jack), that the Java\nAPI framework uses.\n\nNative C/C++ libraries\n----------------------\n\n\nMany core Android system components and services, such as ART and HAL, are\nbuilt from native code that requires native libraries written in C and C++.\nThe Android platform provides Java framework APIs to expose the functionality\nof some of these native libraries to apps. For example, you can access\n[OpenGL ES](/develop/ui/views/graphics/opengl/about-opengl) through the\nAndroid framework's [Java OpenGL API](/reference/android/opengl/package-summary) to add\nsupport for drawing and manipulating 2D and 3D graphics in your app.\n\n\nIf you are developing an app that requires C or C++ code, you can use the\n[Android NDK](/ndk) to access some of these [native platform libraries](/ndk/guides/stable_apis) directly from\nyour native code.\n\nJava API framework\n------------------\n\n\nThe entire feature-set of the Android OS is available to you through APIs\nwritten in the Java language. These APIs form the building blocks you need to\ncreate Android apps by simplifying the reuse of core, modular system\ncomponents and services, which include the following:\n\n- A rich and extensible [view\n system](/guide/topics/ui/overview) you can use to build an app's UI, including lists, grids, text boxes, buttons, and even an embeddable web browser\n- A [resource manager](/guide/topics/resources/overview), providing access to non-code resources such as localized strings, graphics, and layout files\n- A [notification\n manager](/guide/topics/ui/notifiers/notifications) that enables all apps to display custom alerts in the status bar\n- An [activity manager](/guide/components/activities/intro-activities) that manages the lifecycle of apps and provides a common [navigation back stack](/guide/components/tasks-and-back-stack)\n- [Content\n providers](/guide/topics/providers/content-providers) that enable apps to access data from other apps, such as the Contacts app, or to share their own data\n\n\nDevelopers have full access to the same [framework APIs](/reference/packages) that Android system apps use.\n\nSystem apps\n-----------\n\n\nAndroid comes with a set of core apps for email, SMS messaging, calendars,\ninternet browsing, contacts, and more. Apps included with the platform have\nno special status among the apps the user chooses to install. So, a\nthird-party app can become the user's default web browser, SMS messenger, or\neven the default keyboard. Some exceptions apply, such as the system's\nSettings app.\n\n\nThe system apps function both as apps for users and to provide key\ncapabilities that developers can access from their own app. For example, if\nyou want your app to deliver SMS messages, you don't need to build that\nfunctionality yourself. You can instead invoke whichever SMS app is already\ninstalled to deliver a message to the recipient you specify."]]