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

Your farts contain information about your health!

Farting is generally a good thing, as the accumul...

Exclusive interview: An article that helps you truly understand DSP advertising

Although DSP and information flow have been aroun...

Big data reveals the top ten cities with the thickest snow in my country

China Weather Network News: There is no winter wi...

Case review | 4,000 precise local university traffic in two days

The word fission may be a bit outdated now. We of...

Is it true that it will rain during Qingming Festival?

Audit expert: Zhan Mingjin PhD, Chinese Academy o...

Campus mobile Internet: a tough piece of fat to swallow

In the minds of entrepreneurs in the mobile Inter...

Closed-loop analysis of B-side channel operations

Industrial Internet is making efforts to penetrat...

After using iPad Pro for a year, Mac users are more accepting of iOS devices

If you have been using Mac for work and suddenly ...

Dr. Mo reviews iPhone 6S: The best smartphone ever

Apple has just released its new smartphone, iPhon...

5 steps to operate Internet users!

As the link closest to users, user operations are...

Differences and comparisons between Vue and WeChat applet

After writing a Vue project and a mini program, I...