[Android plug-in] Introduction to plug-in (componentization and plug-inization)

[Android plug-in] series of blogs:


Article Directory





1. Componentization and plug-inization



Componentization is to divide the application into several Module modules, and each module is called a component;

In componentized projects, there are two modes, "integrated mode" and "component mode";

In the development process of "component mode" These components can operate independently , in the "integrated mode", these components interdependent assembled into a APK installation package;


Disadvantages of component development:

Multiple modules must be developed concurrently, and the modules depend on each other. If a module is modified, it must be repackaged;

Plug-in development solves the above problems;


Plug-inization splits the application into several modules, among which are  1 1 1A "host" module , a number of "plug-in" modules;

In the final packaging, separate the "host" module and the "plug-in" module for packaging;

The "host" module and the "plug-in" module are each a separate apk installation file;


In plug-inization, the "host" module and the "plug-in" module can be compiled separately without affecting each other. Each module can be developed concurrently, and the "host" module can dynamically update the plug-in.





Two, plug-in example



For example, large-scale applications such as Alipay provide hundreds of small application modules inside, and it is impossible to integrate them during development. The main body of these software is only about 100 MB, and it is impossible to include all applications. ;

Distinguish between native components and Web components: In large applications, some applications use WebView to embed front-end applets, and some are remote components. In "Developer Options", turn on the "Display Layout Boundary" option. If it is WebView, there is only one frame. , If it is a native component, the corresponding TextView, ImageView, etc. have their own boundaries. With the help of the layout boundary display, it can be distinguished whether the third-party applet is a front-end WebView interface or a native application;

Turn on the "Show layout borders" option:

Insert picture description here

Alipay main interface effect: The main interface is a native interface;

Insert picture description here

The Ele.me interface is the WebView interface, the main content is the front-end applet development;

Insert picture description here

The stock module of the wealth management module is a native application;

Insert picture description here

The main framework of Alipay is an Android native application, and the third-party functions and applets are basically web front-end pages;

The current development trend of such applications is to replace native applications with Web applications;


Native applications such as stock modules are generally not packaged in Alipay when they are developed. Instead, their plug-in apk is dynamically deployed through a plug-in mechanism;

When this kind of software is opened for the first time, you need to download the plug-in apk of the module and install it. At this time, it will be stuck below, and then you can access it smoothly;





Third, the introduction of plug-in standards



In plug-inization, the "host" module and the "plug-in" module can be compiled separately without affecting each other, each module can be developed concurrently, and the "host" module can dynamically update the plug-in;

The "host" module is the currently running application, and the "plugin" module is the apk file packaged after the downloaded plugin module is compiled;

Without installing the plug-in apk, call the functions in the plug-in, such as Activity, Service, code logic, etc.;


Not any apk file can be accessed into the "host" plug-in, the apk to be accessed must meet certain standards;

The apk plugin is not installed, so there is no context. When calling the Activity interface in the plugin, you need to pass the context to the plugin’s Activity.