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

Foreign server rental price list, overseas server rental

Foreign server rental price list, overseas server...

Apple iOS's closed system has created an unknown gray industry chain

At the end of 2015, with the imprisonment of Xu, ...

How to promote children's growth? These exercises can help!

The height of children is a problem that many par...

Baidu searched for 18 details of ocpc

Baidu Big Search ocpc was launched in the second ...

Meizu Blue has been released, but has Meizu figured it out?

For a good product, why must I rely on low prices...

In 2021, how to seize the new marketing opportunities brought by live streaming?

Today, we will focus more on analyzing the overal...

A comprehensive summary of the latest self-media monetization methods in 2017!

Q: Why do you do self-media ? Almost 10 out of 10...

10 questions and answers about brand deductions on Xiaohongshu

Recently, brand partners have been discussing the...