平台架構
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 是採用 Linux 的開放原始碼軟體堆疊,適用於多種裝置和板型規格。圖 1 顯示 Android 平台的主要元件。
圖 1 Android 軟體堆疊。
Linux kernel
Android 平台的基礎是 Linux kernel。舉例來說,Android 執行階段 (ART) 需要 Linux kernel 才能執行基本功能,例如執行緒和低階記憶體管理。
使用 Linux kernel 可讓 Android 善用關鍵安全性功能,並讓裝置製造商為知名核心開發硬體驅動程式。
硬體抽象層 (HAL)
硬體抽象層 (HAL) 提供標準介面,可讓裝置硬體功能向較高層級的 Java API 架構公開。HAL 內含多個程式庫模組,每個模組都實作特定類型硬體元件 (例如相機或藍牙模組) 的介面。當架構 API 呼叫存取裝置硬體時,Android 系統會載入該硬體元件的程式庫模組。
Android 執行階段
在搭載 Android 5.0 (API 級別 21) 以上版本的裝置中,每個應用程式都會以自己的程序執行,並有專屬的 Android 執行階段 (ART) 執行個體。ART 會編寫在低記憶體裝置上執行的虛擬機器,方法是執行 Dalvik Executable 格式 (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 應用程式所需的建構模塊,包括:
- 豐富且可擴充的檢視畫面系統,可用來建構應用程式 UI,包括清單、格線、文字方塊、按鈕,甚至是嵌入式網路瀏覽器
- 資源管理員:提供非程式碼資源的存取權,例如本地化字串、圖像和版面配置檔案
- 通知管理員可讓所有應用程式在狀態列中顯示自訂快訊
- 活動管理員:管理應用程式生命週期,並提供常見的導覽返回堆疊
-
內容供應器,可讓應用程式存取其他應用程式 (例如「聯絡人」應用程式) 的資料,或分享自己的資料。
開發人員可以存取 Android 系統應用程式所用的架構 API。
系統應用程式
Android 隨附一組核心應用程式,可用於電子郵件、簡訊、日曆、網際網路瀏覽、聯絡人等。在這個平台納入的應用程式中,使用者選擇安裝的應用程式不會顯示特殊狀態。因此,第三方應用程式可以成為使用者的預設網路瀏覽器、簡訊訊息工具,甚至是預設鍵盤。某些例外狀況,例如系統的「設定」應用程式。
系統應用程式既可以做為對使用者的應用程式使用,也能提供開發人員能夠透過其應用程式存取的主要功能。舉例來說,如果您想讓應用程式傳送簡訊,就不必自行建構這項功能。您可以改為叫用已安裝的簡訊應用程式,藉此傳送訊息給指定的收件者。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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."]]