The five-tier architecture of Android

The initial Android system framework is divided into five layers (kernel layer, hardware abstraction layer, system runtime layer, application framework layer, application layer).

Wikipedia later found the Android system framework as above, missing a hardware abstraction layer HAL (GPS, Wi-Fi, Camera… .).

Look from the bottom up

1. The Linux kernel layer

The underlying layer of Android is based on the Linux operating system, and the strong scalability of the Linux system driver development makes the Android embedded system more extensive, which is also the reason for the emergence of so many mobile phone manufacturers. Each manufacturer’s hardware will have some slight differences, which makes Android has a high portability. The Linux kernel provides Android with system security, memory management, process management, and more.

2. Hardware Abstraction Layer (HAL)

Define hardware “driver” interfaces to reduce coupling between Android and hardware. The abstraction of hardware protects the intellectual property of hardware vendors, since Linux follows the GLP protocol (anti-copyright, all drivers should be open source).

3. System Runtime layer (C library layer, Android runtime library)

A) Because it contains the basic library of system operation, because most of these libraries are implemented by C/C ++, so it is called C library layer. (we know SQLite, OpenGL, libc++, SSL, etc.)

B) Android runtime library: core library and ART (Android 5.0 API: 21 is Dalvik).

  • Dalvik uses JIT compiler (just-in-time) to interpret bytecode into machine code, optimizes dex file into Odex file during application installation, and re-compiles and runs the application every Time it is started, so the performance is low.
  • ART uses AOT precompile (Ahead-of-time) to precompile bytecode files into machine code when the application is installed. The application is fast to start and run, but it consumes more storage space and takes a long Time to install.

4. Application Framework Layer (Java Library)

They are generally written in Java and provide API interfaces for upper-layer applications, including some system-level server process implementations. These apis form the building blocks needed to create Android applications, and they simplify the reuse of core modular system components and services.

5. Application layer

Android comes with a core set of apps for email, messaging, calendar, Internet browsing and contacts. Apps that come with the platform have no special status, just like apps that users can choose to install. So third-party apps can become users’ default web browser, SMS Messenger, and even their default keyboard (with some exceptions, such as the system’s Settings app).

System applications are available to users’ applications and provide major functions that developers can access from their own applications. For example, if your application wants to send SMS messages, you don’t need to build the feature yourself, you can instead call your installed SMS application to send messages to the recipient you specify.

conclusion

This is the five-tier architecture of Android

Then I found a software stack diagram of the current five-tier architecture on the official website

Ps: The biggest difference is ART and Dalvik in Android Runtime.

extension

According to the official documentation of Android Runtime (ART) and Dalvik. We can generally know that ART is not only different from Dalvik in compilation mechanism, but also optimized in GC.

Ps: In Dalvik, applications often find that calling system.gc () explicitly helps to facilitate garbage collection (GC). In ART, this is less necessary, especially if you need garbage collection to prevent GC_FOR_ALLOC types or reduce fragmentation. You can verify which runtime is being used by calling System.getProperty("java.vm.version"). If ART is used, the value of this attribute should be "2.0.0" or higher.

Ps2: A compact garbage collector is being developed as part of the Android Open Source Project (AOSP) to improve memory management. What is a compact garbage collector? I think we can use compact technology when we implement dynamic partition allocation in operating system. In fact, it is the same principle.

Extension 2 (a practical matter)

This problem came across me not long ago. Because he is AndroidRuntime error, then inside a dalvik. System. PathClassLoader error.

 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.readoceanlive, PID: 20650
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.readoceanlive-haRcNqfDg7KbAYrcIuKKQg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.readoceanlive-haRcNqfDg7KbAYrcIuKKQg==/lib/arm64, /system/lib64, /product/lib64]]] couldn't find "libliveplayer.so" at java.lang.Runtime.loadLibrary0(Runtime.java:1012) at java.lang.System.loadLibrary(System.java:1672)Copy the code

How do you undo this error? Use AS — > Run ‘app’ — > Real running — > Open once installed — > Crashes

AS — > Build — > Analyze apk… I checked my APK

When I click on Run ‘app’, it becomes the image below

My lib is missing, but the app works fine when I download apK to my phone and install it. (instead of clicking Run ‘app’), so far I don’t know why? (Guess Run ‘app’ did something bad, optimized, etc.)

If you know the big guy can leave a message to inform, very grateful.