Overview of Android system architecture

Source: Internet
Author: User

The architecture diagram of Android is as follows. The figure shows that android is divided into three parts based on the functional structure and target audience:

  • Application: contains all applications running on Android devices, which are user-oriented in the Android system.
  • Core part: The core functions of the Android system, including the application framework and core class libraries. Developers of every Android Application Develop applications on this basis.
  • Underlying part: It mainly refers to the Linux operating system and related drivers of the android host. Generally, only hardware vendors and developers engaged in Android porting can develop based on this.

In addition to the preceding division method, android can be divided into the following layers based on the actual system architecture model:

  • Application Layer
  • Framework Layer
  • Runtime
  • Core class library
  • Hardware Abstraction Layer
  • Linux Kernel

The subsequent content of this article will analyze the above layers one by one.

1.1.1 Application Layer

For ordinary users, the advantages and disadvantages of the mobile platform can only be determined through specific applications. Even if a mobile platform has the most gorgeous technology, but if it cannot provide users with the most handy applications, at most it can only win the title of the unsung king, and cannot grasp the user's heart, win market recognition.

The Android Application layer is composed of all applications running on Android devices. It includes not only system applications such as calls, text messages, and contacts (pre-installed on mobile devices along with Android ), other third-party applications subsequently installed on the device are also included.

Third-party applications are developed based on the SDK (software development kit) provided by Android and are subject to SDK interface constraints. System Applications pre-installed on devices can call the interfaces and modules of the entire framework layer, many of which are hidden in the SDK. Therefore, system applications have more rights than third-party applications.

Android applications are developed based on the Java language. However, in many applications (especially games), large-scale computation and graphic processing are required, and open-source C/C ++ class libraries. Java may cause low execution efficiency and high porting costs. Therefore, in Android development, developers can use C/C ++ to implement underlying modules and add the JNI (Java Native Interface) interface to interact with the upper-layer Java implementation, then, use the cross-compilation tool provided by Android to generate a class library and add it to the application.

To allow application developers to bypass the framework layer and directly use a specific class library of the Android system, Android also provides the ndk (Native Development Kit), which consists of some interfaces of C/C ++, developers can use it to call specific system functions more efficiently.

However, on Android, developers can only use C/C ++ to write function libraries, rather than the entire application. This is because core mechanisms such as interface rendering and process scheduling are deployed at the framework layer and implemented in Java, applications can be identified, loaded, and executed only when specific Java modules and configuration information are written according to their prescribed patterns.

TIPS: the Android. App. nativeactivity class has been added since Android 2.3 (API 9). It is implemented by calling the predefined JNI interface. Developers can use the C/C ++ language to implement specific functions based on ndk. This means that developers can implement the entire application only through the C/C ++ language. This is a good news for game developers. However, since the control does not implement native in Android, general application developers still need to use Java to implement the upper-layer interface.

1.1.2 framework layer

The framework layer is the core of the Android system. It embodies the design philosophy of the Android system. Before Android, there were many mobile platforms based on Linux kernel. As an example of success beyond the predecessors, the design of the framework layer is the key for Android to stand out.

The framework layer consists of multiple system services, including Component Management Services, Window Management Services, Geographic Information Services, power management services, and call management services. All services are hosted in the system core process. During running, each service occupies an independent thread, send messages and transmit data to each other through the inter-process communication mechanism (IPC.

Applications at the application layer are always dealing with these system services. Each operation that constructs a window, processes user interaction events, draws an interface, obtains the current geographical information, and understands device information is implemented with the support of various system services.

For developers, the most intuitive embodiment of the framework layer is the SDK, which implements the functions required by the application through a series of Java functional modules. The SDK design determines the development mode, development efficiency, and functional scope of upper-layer applications. Therefore, it is necessary for developers to pay attention to the changes in the SDK. The birth of each new version of the SDK means that some old interfaces will be adjusted or discarded, some new interfaces and functions are coming soon. Developers not only need to check and pay attention to the modified interfaces to check the application compatibility, but also adopt corresponding policies to adapt to these changes. More importantly, developers also need to track new interfaces, find opportunities to improve applications, and even seek to develop new applications.

From the perspective of system design, Android expects the framework layer to be the core of all applications. It participates in every operation at the application layer for global coordination. The biggest feature of Android applications is component-based design. Each application is composed of several components. communication channels are not established between components. Instead, messages are centrally scheduled and transmitted through system services at the framework layer. This design method adds an intermediate layer that understands the status of all components and can be more intelligently coordinated, thus improving the flexibility of the entire system.

1.1.3 Runtime

Like all Java program running platforms, Android provides runtime support for Java programs to achieve secondary compilation in the runtime stage.

Android runtime consists of the Java core class library and Java Virtual Machine Dalvik. The core Java class library covers the basic java libraries used at the android framework layer and application layer, including the Java object library, file management library, and network communication library.

Dalvik is a Java Virtual Machine tailored for Android. It is responsible for dynamically parsing and executing applications, allocating space, and managing object lifecycles. If the framework layer is the entire android brain and determines the design features of Android applications, Dalvik is the heart of Android, providing motivation for Android applications and determining their execution efficiency.

Dalvik is specially designed for high-end devices, unlike the j2mvirtual machine designed for low-end mobile devices. Instead of using a stack-based virtual machine architecture, it adopts a register-based virtual machine architecture design. Generally, stack-based virtual machines have little hardware dependency, and the generated applications save space and can adapt to more low-end devices. Register-based virtual machines, the hardware threshold is higher, and compiled applications may consume a little more storage space. However, the execution efficiency is higher, and the high-end hardware (mainly processor) capabilities can be used more effectively.

Dalvik does not use the traditional Java binary code (javabytecode) as an intermediate file for one compilation, but uses the new binary code format file. Dex. During the compilation process of the android application, it will be converted into several. class files and then converted into a. Dex file. During the conversion process, Android will escape the commands in some. class files and replace them with the Opcodes Instruction Set specific to Dalvik to improve the execution efficiency. At the same time,. Dex will integrate duplicate information in multiple. class files, optimize and adjust the redundancy part globally, and merge repeated constant definitions to save the space consumed by the constant pool. This makes the final. Dex file more streamlined than the. jar file compressed and packaged by the. Class file.

To improve the execution efficiency of Android applications, Dalvik has been optimized in various aspects from the garbage collection (GC) to the compiler. You can often hear the following message: "the new version of Android is X times more efficient than the previous version ." This is mostly about improving the Dalvik effect. In Android 2.2, Dalvik introduced support for JIT (just-in-time) compilation, which improved the execution efficiency of upper-layer applications by 2 ~ 4x, opening a new chapter in Android development.

As most application developers do not need to understand the details of the android runtime, this book will not detail the content related to the android runtime in the future, interested readers, you can refer to the relevant materials and source code separately.

1.1.4 core class library

For the framework layer, the core class library is its "excellent help ". Every android system upgrade shows the changes in the framework layer SDK, adding new functions and providing new interfaces. Behind these new features, the core class libraries are excellent.

The core class library consists of a series of binary dynamic libraries, which are usually developed using C/C ++. Compared with the system service at the framework layer, the core class library cannot run independently in the thread, but needs to be loaded into the process space by the System Service and called through the JNI interface provided by the class library.

There are two main sources of core class libraries. One is the system native class library. To improve the execution efficiency of the framework layer, Android uses C/C ++ to implement some of its key performance modules, such as the resource file management module and basic algorithm library. The other is third-party class libraries, most of which are transplanted to excellent open-source projects. They are an important guarantee for Android to provide rich functions, such as multimedia processing for Android, relying on the support of open-source project opencore, the core implementation of browser controls is transplanted from WebKit, while the database function is benefited from SQLite. Android encapsulates a layer of JNI interface for all the third-party class libraries transplanted for the framework layer to call.

To help developers in the game and graphic image processing fields build more efficient applications, Android provides core libraries such as the mathematical function library and OpenGL library to developers in the form of ndk, developers can build algorithms and draw images more efficiently based on ndk. From a practical perspective, as long as the header file information of the underlying class library can be obtained, developers can go beyond the ndk limit and use interfaces of other core class libraries for development. However, the danger of doing so lies in poor compatibility. Android may replace or modify some class library interfaces or implementations during version changes, which causes applications dependent on these class libraries to fail to run. Ndk provides stable class library implementations without any modifications to ensure the upward compatibility of ndk applications.

1.1.5 Hardware Abstraction Layer and Linux Kernel

The Android system is not designed from scratch, but built on the Linux kernel. The narrow Android system mainly refers to the Linux kernel and above layers. From the operating point of view, they only run some processes on the Linux system and are not a complete system, without the support of Linux, just as a fish leaves the water and cannot run.

The greatest value of Linux for Android is its powerful portability. Linux runs in a variety of chip architectures and hardware environments, and relies on its Android system, it also has powerful portability. At the same time, Linux is like a bridge that connects the upper-layer Implementation of Android with the underlying hardware so that they do not have to be directly coupled, thus reducing the difficulty of porting.

The hardware abstraction layer (HAL) is a set of interface standards defined by Android vendors. It provides interface support for the framework layer. vendors need to implement the corresponding functions based on the defined interfaces.

------------------------------

This article is excerpted from the book Android development essentials, by fan huaiyu, published by the Mechanical Industry Publishing House.

[Content Overview]

How can we write Android applications that are closer to Android design concepts and can run more efficiently and reliably? It is one of the most important methods to understand the underlying implementation details through the android source code! However, the android system is too large, the source code implementation is complicated, and the technical threshold and time cost for learning are high. Is there a way to help developers understand Android Application Development in depth and quickly master the knowledge required to write high-quality Android applications without being overwhelmed by a large number of implementation details at the underlying layer? This book provides a perfect answer to this question! It extracts the "essence" and "Key Points" of Android development from the complicated source code of Android, stripped away a lot of trivial underlying implementation details, and made a high summary and summary, it not only helps developers quickly understand the design concept of the entire android system from a macro perspective, but also helps developers quickly grasp the principles of core knowledge points from the micro perspective, thus writing high-quality Android applications.

This book consists of 13 chapters, which are logically divided into four parts. Part 1 (1 ~ Chapter 2): Chapter 1st introduces the Android system architecture, core modules, and design ideas, so that readers can truly understand the design concept; chapter 2 describes how to obtain, compile, read, and edit the android source code. Part 2 (3 ~ Chapter 6): Chapter 3rd elaborates on the design concepts and important features of the android component mechanism, and introduces in detail the methods and principles of the four components; chapter 2 explains the intent mechanism of intent objects and Android, and explains how Android integrates components from different applications and processes; chapter 2 describes the life cycles of each component in Android, including the process model and thread model of the component. Chapter 5th describes the data transmission solution between components from the perspective of development, and their advantages and disadvantages and applicable scenarios. Part 3 (7 ~ Chapter 8): Chapter 7th provides an in-depth explanation of the android Control Framework, and analyzes the implementation and use of important controls based on actual projects. It also includes
4.0 interface development practices "excellent"; chapter 8th analyzes the android resource system and analyzes the underlying processing of resources by Android. Part 4 (9 ~ Chapter 13): Chapter 9th describes the data storage structure of Android and the usage of different data storage modes. Chapter 10th analyzes various network connection methods of Android, covers NFC and wi-fi-Based P2P connections. Chapter 11th describes the implementation of the android positioning service, address service, and map service framework; chapter 5 carefully analyzes the implementation mechanisms of various Android multimedia functions. Chapter 4 analyzes the implementation details of some modules with special features in Android.

[Author's profile]

Fan huaiyu, a senior Android Development Engineer and graduated from Tsinghua University. He has been engaged in mobile development for many years and has extensive experience in Android development. I once worked in NetEase youdao and completed the development of youdao dictionary Android edition, Netease mobile app Android edition, Netease Android edition, and other projects. Now I work in the peas lab, designs and develops pods 2.0.

Author Weibo: @ duguguiyu personal site: http://flyvenus.net

Http://vdisk.weibo.com/s/a5xZe (sample download)

[Add to favorites] http://book.douban.com/subject/11530748/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.