1、Android 系统架构详解Android 系统架构由 5 部分组成,分别是:Linux Kernel、Android Runtime、Libraries 、Application Framework、Applications。1、Linux KernelAndroid relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts
2、as an abstraction layer between the hardware and the rest of the software stack.Android 基于 Linux 2.6 提供核心系统服务,例如:安全、内存管理、进程管理、网络堆栈、驱动模型。Linux Kernel 也作为硬件和软件之间的抽象层,它隐藏具体硬件细节而为上层提供统一的服务。 如果你学过计算机网络知道 OSI/RM,就会知道分层的好处就是使用下层提供的服务而为上层提供统一的服务,屏蔽本层及以下层的差异,当本层及以下层发生了变化不会影响到上层。也就是说各层各尽其职,各层提供固定的 SAP(Service
3、 Access Point) ,专业点可以说是高内聚、低耦合。 如果你只是做应用开发,就不需要深入了解 Linux Kernel 层。2、Android RuntimeAndroid includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.Android 包括一个核心库的集合,她们提供了 Java 编程语言的核心库中的绝大多数功能。Every Android applicati
4、on runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, a
5、nd runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included “dx“ tool.每一个 Android 应用都在她自己的进程中运行,该进程也属于某个 Dalvik 虚拟机的实例。Dalvik 被设计成能让设备高效地运行多个虚拟机。Dalvik 虚拟机执行的是.dex 结尾的Dalvik 可执行文件格式,该格式被优化为最小内存使用。虚拟机是基于寄存器的,并且运行那些 Java 编程语言所编译的类,这些类被内置的 dx 工具转
6、换为 .dex 格式。The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.Dalvik 虚拟机依赖 Linux 内核来提供底层的功能,比如线程和低级内存管理。Android 包含一个核心库的集合,提供大部分在 Java 编程语言核心类库中可用的功能。每一个 Android 应用程序是 Dalvik 虚拟机中的实例,运行在他们自己的进程中。Dalvik 虚拟机设计成,在一个设备可以高效地运行多个虚拟机。Dalv
7、ik 虚拟机可执行文件格式是.dex,dex 格式是专为 Dalvik 设计的一种压缩格式,适合内存和处理器速度有限的系统。 大多数虚拟机包括 JVM 都是基于栈的,而 Dalvik 虚拟机则是基于寄存器的。两种架构各有优劣,一般而言,基于栈的机器需要更多指令,而基于寄存器的机器指令更大。dx 是一套工具,可以将 Java .class 转换成 .dex 格式。一个 dex 文件通常会有多个.class。由于dex 有时必须进行最佳化,会使文件大小增加 1-4 倍,以 ODEX 结尾。 Dalvik 虚拟机依赖于 Linux 内核提供基本功能,如线程和底层内存管理。3、LibrariesAnd
8、roid includes a set of C/C+ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:Android 包括了一个 c/c+库的集合,她们被 Android 系统的众多组件所使用。通过Android 的应用框架,这些功能被开放给开发者。其中的一些核
9、心库如下:System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices系统 C 库一个继承自 BSD 的标准 C 系统实现(libc) ,被调整成面向基于 linux 的嵌入式设备。Media Libraries - based on PacketVideos OpenCORE; the libraries support playback and recording of many popular a
10、udio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG媒体库基于 PacketVideos OpenCORE;该库支持许多流行音频/ 视频的录制与回放,当然还支持静态的图片文件,包括 MPEG4, H.264, MP3, AAC, AMR, JPG, and PNGSurface Manager - manages access to the display subsystem and seamlessly composites 2D a
11、nd 3D graphic layers from multiple applications表面管理器管理显示子系统,并能无缝地组合多个应用的 2D 和 3D 图像层。LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web viewLibWebCore一个流行的 web 浏览器引擎,她同时支持 Android 浏览器和嵌入式的web 视图。SGL - the underlying 2D graphics engineSGL底层的 2D 图像引擎3D
12、 libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer3D libraries基于 OpenGL ES 1.0 APIs 的一个实现;该库或是使用硬件的 3D 加速,或是使用内置的高度优化的 3D 软件光栅。FreeType - bitmap and vector font rende
13、ringFreeType 位图和矢量字体渲染SQLite - a powerful and lightweight relational database engine available to all applicationsSQLite 一个强大而轻量的关系数据库引擎,对所有应用可用。4、Application Framework 应用框架By providing an open development platform, Android offers developers the ability to build extremely rich and innovative applica
14、tions. Developers are free to take advantage of the device hardware, access location information, run background services, set alarms, add notifications to the status bar, and much, much more.通过提供一个开放的开发平台,Android 提供给开发者建立极其丰富和创新应用的能力。开发者自由地享有硬件设备的优势,访问本地信息,运行后台服务,设置警示,向状态栏添加通知,还有更多Developers have f
15、ull access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced
16、by the framework). This same mechanism allows components to be replaced by the user.开发者能完全访问与核心应用所用的同一个框架 APIs。应用架构被设计得能够简化组件的重用;任何应用都可以发布其功能,而其他的应用也就可以使用这些功能(安全限制主题由框架增强) 。同样的机制允许用户替换组件。Underlying all applications is a set of services and systems, including:在所有的应用之下,有一系列的服务与系统,包括:A rich and extensi
17、ble set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser丰富且可扩展的一系列视图 Views,可用于建立应用;包括: lists,grids,text boxs, buttons,以及一个嵌入式的 web 浏览器。Content Providers that enable applications to access data from other applications (
18、such as Contacts), or to share their own data内容提供者,使应用能访问其他应用的数据(比如电话本) ,或是分享他们自己的数据。A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files资源管理器,提供访问非代码资源的能力,比如本地化字符串,图形和布局文件。A Notification Manager that enables all applications to display cus
19、tom alerts in the status bar通知管理器,使所有的应用都能在状态栏显示自定义的通知。An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack活动管理器,管理应用的生命周期,并提供了一个通用的导航后台。For more details and a walkthrough of an application, see the Notepad Tutorial.更多细节,和一个应用的演练,请看“记事本教程”。5、Appli
20、cationsAndroid will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.Android 装配一个核心应用程序集合,包括电子邮件客户端、SMS 程序、日历、地图、浏览器、联系人和其他设置。所有应用程序都是用 Java 编程语言写的。更加丰富的应用程序有待我
21、们去开发! 从上面我们知道 Android 的架构是分层的,非常清晰,分工很明确。Android 本身是一套软件堆迭 (Software Stack),或称为软件迭层架构 ,迭层主要分成三层:操作系统、中间件、应用程序。从上面我们也看到了开源的力量,一个个熟悉的开源软件在这里贡献了自己的一份力量。Features 特性Application framework enabling reuse and replacement of components应用框架:使能重用和可替换的组件Dalvik virtual machine optimized for mobile devicesDalvik
22、虚拟机:为移动设备而优化Integrated browser based on the open source WebKit engine集成浏览器:基于开源的 WebKit 引擎。Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)优化的图形:自定义的 2D 图形库;基于 OpenGL ES 1.0 规范的 3D 图形(可选的硬件加速)SQLite for
23、structured data storageSQLite:结构化的数据存储Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)媒体支持:通用音频、视频,还有图像格式(MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)GSM Telephony (hardware dependent)GSM 电话:(依赖硬件)Bluetooth, EDGE, 3G, and WiFi (hardware dependent)Camera, GPS, compass, and accelerometer (hardware dependent)照相机,GPS,指南针和加速度计:(依赖硬件)Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE丰富的开发环境:包括一个设备模拟器,调试工具,存储和性能简介,还有一个Eclipse IDE 的插件。