fw新学员分享的官方Android 平台架构说明文章

Android 平台架构 (Android Platform Architecture)

背景:

非常感谢新学员朋友在学习马哥安卓的framework入门课程时候,发现了一个官方的安卓架构图的网页,这个官方网页解释安卓架构图也很全面,比我们自己总结的可能还是权威和全面一下,这里分享给大家,虽然对于很多老学员来说内容简单都完全理解了,但是也可以看看google官方的文档是如何描述的,是不是和我们理解都完全一直呢?

英文原版

Android is an open source, Linux-based software stack created for a wide array of devices and form factors. The following figure shows the major components of the Android platform.
在这里插入图片描述

(Illustration: The Android software stack)

Linux kernel

The foundation of the Android platform is the Linux kernel. For example, the Android Runtime (ART) relies on the Linux kernel for underlying functionalities such as threading and low-level memory management.

Using a Linux kernel lets Android take advantage of key security features and lets device manufacturers develop hardware drivers for a well-known kernel.

Hardware abstraction layer (HAL)

The hardware abstraction layer (HAL) provides standard interfaces that expose device hardware capabilities to the higher-level Java API framework. The HAL consists of multiple library modules, each of which implements an interface for a specific type of hardware component, such as the camera or Bluetooth module. When a framework API makes a call to access device hardware, the Android system loads the library module for that hardware component.

Android runtime (ART)

For devices running Android version 5.0 (API level 21) or higher, each app runs in its own process and with its own instance of the Android Runtime (ART). ART is written to run multiple virtual machines on low-memory devices by executing Dalvik Executable format (DEX) files, a bytecode format designed specifically for Android that’s optimized for a minimal memory footprint. Build tools, such as d8, compile Java sources into DEX bytecode, which can run on the Android platform.

Some of the major features of ART include the following:

  • Ahead-of-time (AOT) and just-in-time (JIT) compilation
  • Optimized garbage collection (GC)
  • On Android 9 (API level 28) and higher, conversion of an app package’s DEX files to more compact machine code
  • Better debugging support, including a dedicated sampling profiler, detailed diagnostic exceptions and crash reporting, and the ability to set watchpoints to monitor specific fields

History: Prior to Android version 5.0 (API level 21), Dalvik was the Android runtime. If your app runs well on ART, then it can work on Dalvik as well, but the reverse might not be true.

Android also includes a set of core runtime libraries that provide most of the functionality of the Java programming language, including some Java 8 language features, that the Java API framework uses.

Native C/C++ libraries

Many core Android system components and services, such as ART and HAL, are built from native code that requires native libraries written in C and C++. The Android platform provides Java framework APIs to expose the functionality of some of these native libraries to apps. For example, you can access OpenGL ES through the Android framework’s Java OpenGL API to add support for drawing and manipulating 2D and 3D graphics in your app.

If you are developing an app that requires C or C++ code, you can use the Android NDK to access some of these native platform libraries directly from your native code.

Java API framework

The entire feature-set of the Android OS is available to you through APIs written in the Java language. These APIs form the building blocks you need to create Android apps by simplifying the reuse of core, modular system components and services, which include the following:

ComponentDescription
View SystemA rich and extensible View System you can use to build an app’s UI, including lists, grids, text boxes, buttons, and even an embeddable web browser
Resource ManagerA Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
Notification ManagerA Notification Manager that enables all apps to display custom alerts in the status bar
Activity ManagerAn Activity Manager that manages the lifecycle of apps and provides a common navigation back stack
Content ProvidersContent Providers that enable apps to access data from other apps, such as the Contacts app, or to share their own data

Developers have full access to the same framework APIs that Android system apps use.

System apps

Android comes with a set of core apps for email, SMS messaging, calendars, internet browsing, contacts, and more. Apps included with the platform have no special status among the apps the user chooses to install. So, a third-party app can become the user’s default web browser, SMS messenger, or even the default keyboard. Some exceptions apply, such as the system’s Settings app.

The system apps function both as apps for users and to provide key capabilities that developers can access from their own app. For example, if you want your app to deliver SMS messages, you don’t need to build that functionality yourself. You can instead invoke whichever SMS app is already installed to deliver a message to the recipient you specify.


中文版本

Android 是一个基于 Linux 的开源软件堆栈,针对多种不同设备类型打造。下图显示了 Android 平台的主要组件。
在这里插入图片描述
(图: Android 软件堆栈)

Linux 内核

Android 平台的基础是 Linux 内核。例如,Android 运行时 (ART) 依赖 Linux 内核来实现底层功能,例如线程处理和低级内存管理。

使用 Linux 内核可让 Android 利用关键安全功能,并让设备制造商能够为知名内核开发硬件驱动程序。

硬件抽象层 (HAL)

硬件抽象层 (HAL) 提供了用于向较高级别的 Java API 框架公开设备硬件功能的标准接口。HAL 由多个库模块组成,每个模块都为特定类型的硬件组件(例如相机或蓝牙模块)实现一个接口。当框架 API 发出调用以访问设备硬件时,Android 系统将为该硬件组件加载库模块。

Android 运行时 (ART)

对于搭载 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 框架(也叫android framework)

您可通过以 Java 语言编写的 API 使用 Android 操作系统的整个功能集。这些 API 是创建 Android 应用所需的构建块的基础,可简化核心、模块系统组件和服务的重复使用,包括以下组件和服务:

组件说明
视图系统丰富且可扩展的 View 系统,可用于构建应用界面,包括列表、网格、文本框、按钮,甚至可嵌入的网络浏览器
资源管理器资源管理器,用于访问非代码资源,例如本地化的字符串、图形和布局文件
通知管理器通知管理器,可让所有应用在状态栏中显示自定义提醒
Activity 管理器Activity 管理器,用于管理应用的生命周期,并提供常见的导航返回堆栈
Content ProviderContent Provider,可让应用访问其他应用(例如"通讯录"应用)中的数据或共享自己的数据

开发者可以完全访问 Android 系统应用使用的相同框架 API。

系统应用

Android 随附一套用于电子邮件、短信、日历、互联网浏览和通讯录等的核心应用。平台随附的应用与用户可以选择安装的应用一样,没有特殊状态。因此,第三方应用可以成为用户的默认网络浏览器、短信应用甚至默认键盘。但有一些例外情况,例如系统的"设置"应用。

系统应用既可用作用户体验应用,又能提供开发者可从自己的应用访问的关键功能。例如,如果您希望应用发送短信,则无需自行构建该功能。您可以改为调用已安装的短信应用,将消息发送给您指定的接收者。


原文地址:
https://mp.weixin.qq.com/s/OoF5mnQokefYNMZv28JjqA

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值