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

Why doesn’t Pinduoduo have a shopping cart?

In October 2019, Pinduoduo's market value sur...

From a Cantonese novice to a Cantonese expert

Friends who often listen to music or watch movies ...

When increasing user growth, how can we retain new users?

Retention of new users is a very important part o...

Building an e-commerce product center from 0 to 1

This series of articles will introduce the produc...

Only 3 tricks are needed to attract traffic and promote Xiaohongshu!

Xiaohongshu App is hailed as a magic tool for you...

Miscellaneous notes on using git

Preface As a developer, if you don't know git...

TikTok Promotion: The essence of TikTok is revealed in 3,000 words!

In the past two months, readers have been leaving...

Projects die in the cold winter, but businesses survive

[[153510]] Three days ago was my first anniversar...

I am so impressed by how information flow advertising is done!

After reading this article, I hope your informatio...