Android dynamic loading: DL framework

Android dynamic loading: DL framework

Today we introduce a new concept: dynamic loading of Android.

First of all, we need to understand what is Android dynamic loading? Android dynamic loading means that we can dynamically call an APK that has not been installed. And this APK can be replaced at any time. This is what we call Android dynamic loading.

So what are the benefits of dynamic loading? As an Android team we can enjoy the following benefits:

1. Hot patch updates can be implemented

2. Can greatly improve the coverage of the new version

3. It can reduce the server's compatibility pressure with old versions of interfaces

4. Improve app startup speed

The principle of dynamic loading:

Android programs are mainly written in Java code, so Android programs have some features of the Java language, such as the reflection mechanism, so we can use the reflection mechanism to implement dynamic loading of programs and call the apk code that is not installed externally. The reflection mechanism in Java programs mainly loads the Class you want to inject into the Jvm through ClassLoader, and Android's dynamic loading is similar, which is to load the apk file into the virtual machine through DexClassLoader.

Today I will mainly introduce an Android dynamic loading framework: DL dynamic loading framework.

This framework is jointly developed by several students on github. You can download the source code on github. The DL framework can realize the plug-in development of Android and fix online problems through real-time hot patches. Users do not need to download the new version specifically to complete the function launch. So what should we know about the use of the DL framework?

First of all, we need to understand that there are three modes of DL usage:

1. depend_on_host: The plugin is completely dependent on the host mode, which is suitable for situations where the host source code can be obtained.

2. depend_on_interface: The mode in which the plug-in partially depends on the host, or the plug-in depends on the interface provided by the host. It is suitable for situations where the host interface can be obtained.

3. main: The mode in which the plugin does not depend on the host. This is the mode recommended by DL.

The above three modes can be adapted to different situations during development:

Mode 1: The plug-in is completely dependent on the host, which is suitable for situations where the host's source code can be accessed. This mode is generally used within the company, and the plug-in can access all the host's code. However, the coupling between the plug-in and the host is relatively high. Once the host moves, the plug-in must also move, which is more troublesome.

Mode 2: The plug-in partially depends on the host, or the plug-in depends on the interface provided by the host, which is suitable for the situation where the host interface can be obtained. In this mode, the host releases some interfaces and implements some interfaces, and then calls them to the plug-in, so that the plug-in can access some services of the host.

Mode 3. This is the mode recommended by DL, and the corresponding project directory is main. In this mode, the host and the plug-in do not need to communicate, and the two are developed independently. The host references the DL jar package (dl-lib.jar), and the plug-in also needs to reference the DL jar package, but it cannot be placed in the libs directory of the plug-in project.

From the above three modes, we can choose one mode to develop our program. Students can study it by themselves and realize their first dynamically loaded APP as soon as possible.

<<:  I've learned a lot. It turns out that Android screen adaptation can be played like this

>>:  Implementing a long connection between Android and the server based on a custom protocol based on Java Socket (Part 2)

Recommend

13 aspects to consider when developing a mobile app

This article is for newcomers to the field of mob...

I want to listen to two songs at the same time, brain: No, I can't do that

I wonder if you have ever had this experience: If...

Kuaishou operation creates a "fast brand" from 0 to 1!

At the beginning of 2022, I became a Kuaishou e-c...

Tips for cold start operation and promotion of Tik Tok account!

“It’s hard to create a new Douyin account now!” R...

Reverse time and rejuvenate! Is the Turritopsis immortal?

References: 1. "On the list of longevity ani...

Content operation, how does Bilibili operate the UP host group?

This article mainly analyzes BiliBili’s product i...

The sun is smiling strangely, what does this indicate?

Have you ever seen the sun smile? Here is a photo...

Inventory: The top ten things in the marketing industry in 2019

2019 is about to end. There is no doubt that this...