1. Android System Architecture
The latest Android system is divided into five-tier six-zone (domain):
- Linux kernel layer (Linux Kernel):TheAndroid system is based on the Linux2.6 core, which provides the underlying drivers for various hardware on Android devices, such as display drivers, audio drivers, Camera driver, Bluetooth driver, Wi-Fi driver, power management, etc.
- Hardware abstraction Layer (Android Hardware abstraction Layer): Android drives hardware in a different way from Linux. Traditional Linux drives completely live in kernel space. Android adds a hardware abstraction layer (HAL, Hardware abstraction layer) to the outside of the kernel, placing part of the drive function in the HAL layer. Why is Android racking up trouble adding a HAL? In order to protect the source code. The Linux kernel uses the GPL, so the hardware manufacturer wants to support the Linux system, and the hardware-driven source code must be exposed in accordance with the GPL protocol. But the source code contains design information for many hardware, which involves the core interests of the hardware manufacturer. With the addition of the HAL layer, the hardware vendor does not need to open all of the driver code.
- System Runtime Layer (libraries): This layer provides major feature support for Android systems through a number of C + + libraries (solibraries ). such as the SQLite library provides database support, OpenGL ES Library provides 3D drawing support, WebKit library provides browser kernel support, etc.;
- Application Framework layer (application framework): This layer primarily provides the various APIsthat may be used to build the application, and some of the core applications that Android comes with are the use of these APIs. Developers can also use the API to build their own applications;
- Application Layer (applications): This layer is mainly used for mobile phone application installation, such as the system comes with contacts, SMS and other programs, or third-party applications
The above is the five-storey five-zone, and one area is the Android Runtime Library (Android runtime), which exists in the libraries layer, which mainly provides some core libraries that allow developers to write Android apps in the Java language. In addition, the Android Runtime library contains the Dalvik virtual machine, which allows each Android app to run in a separate process and have its own Dalvik virtual machine instance. Compared to Java virtual machines, Dalvik is specifically designed for mobile devices, which are optimized for mobile memory and CPU performance.
2, expand 2.1 Dalvik virtual machine
Android applications are written in Java, and Linux libraries, including Hal, are written by C + +, which is bridged by the Dalvik virtual machine. When an app is running, a Dalvik virtual machine is included in the process space. Java programs are compiled into bytecode files and run in Dalvik virtual machines. Based on the requirements in the Java code, Dalvik invokes the functionality written by the lower-level C + + through JNI (Java Native Interface). JNI is an interface that calls a C + + module from Java. Because of the standardization of the upper interface, bytecode can be run smoothly across platforms.
Dalvik virtual machine inside is a "virtual" process space, has its own stack and heap, management code running process. If this is not sufficient for "virtual" process space, the Dalvik built-in garbage collection (garbage collection) mechanism automatically empties objects that are no longer used on the heap. Automatic garbage collection simplifies the programmer's work, but it's slower. Manual memory management is efficient, but requires more programming and is prone to mistakes.
2.2 JNI
Http://www.2cto.com/kf/201502/377185.html
Http://www.cnblogs.com/mandroid/archive/2011/06/15/2081093.html
Android System Architecture