Android-based application plug-in method, device, storage medium and electronic device

By dynamically judging and updating plug-ins in Android applications, loading plug-in resources using custom class loaders and AssetManager, and establishing communication between plug-ins and host applications, the problem of overall updates in the existing technology is solved, and independent upgrades and efficient development of plug-ins are realized.

CN118760480BActive Publication Date: 2025-03-11BEIJING BLUE RHINO INFORMATION TECH CO LTD +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410724414.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2025-03-11
Estimated Expiration
2044-06-05

AI Technical Summary

Technical Problem

In the prior art, application upgrades usually require overall host project updates, resulting in frequent releases and reducing application development efficiency.

Method used

By determining whether the plug-in needs to be upgraded when the host application is cold-started, dynamically obtain the new version of the plug-in and perform local installation, use a custom class loader and AssetManager to load plug-in classes and resources, start the target Android native components and establish communication between the plug-in and the host application.

Benefits of technology

The plug-in independent upgrade has been achieved, which avoids overall updates of the host project, reduces frequent releases, and improves application development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760480B_ABST
    Figure CN118760480B_ABST
Patent Text Reader

Abstract

The present application relates to an Android-based application plug-in method, device, storage medium and electronic device, and to the technical field of application plug-in, wherein the method comprises: in the case of a cold start of a host application, determining whether the locally installed plug-in of the host application needs to be upgraded; if so, obtaining the plug-in package corresponding to the new version of the plug-in from the server corresponding to the host application, and installing it locally to obtain the installed plug-in; loading the class in the installed plug-in through a preset custom class loader; loading the plug-in resources in the installed plug-in through a preset custom AssetManager and a custom Resources object; starting the target Android native component in the installed plug-in, and establishing communication between the installed plug-in and the host application. The present application has the effect of reducing the frequent release of host projects and improving the efficiency of application development.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of application plug-in, and in particular to an Android-based application plug-in method, device, storage medium and electronic device. Background Art

[0002] Application plug-in is a software architecture design method that allows developers to decompose a large application into multiple independent modules, which are usually called plug-ins. Each plug-in is an independent functional unit of the application, which can contain its own code, resources and even interface, and each plug-in can be independently updated and deployed, thereby improving the flexibility and maintainability of the application to a certain extent. The maintainability of the application is closely related to the application upgrade. Among them, application upgrade can be understood as application software upgrade update, which refers to the version update of the application already installed on the user's device. The update includes a variety of contents, aiming to improve the performance and stability of the application software, add new functions, and improve the user experience.

[0003] At present, the common way to upgrade applications is to upgrade the application based on the overall update of the host project. The host project refers to the project or project that plays a management role in application development. The overall update of the host project involves replacing the entire software package of the application and finally releasing the host project, that is, the process of pushing the new version of the application to users. Once the application needs to perform rapid functional iteration, the host project will need to be released frequently, reducing the efficiency of application development. Summary of the invention

[0004] In order to reduce the frequent release of host projects and improve application development efficiency, the present application provides an Android-based application plug-in method, device, storage medium and electronic device.

[0005] In a first aspect of the present application, a method for application plug-in based on Android is provided, which specifically includes:

[0006] In the case of a cold start of the host application, determining whether a locally installed plug-in of the host application needs to be upgraded;

[0007] If so, obtain the plug-in package corresponding to the new version of the plug-in from the server corresponding to the host application, and install it locally to obtain the installed plug-in;

[0008] Loading classes in the installed plug-in through a preset custom class loader, wherein the custom class loader is used to load classes in different types of plug-ins in the host application;

[0009] Load the plug-in resources in the installed plug-in through the preset custom AssetManager and custom Resources object, wherein the custom AssetManager and the custom Resources object are used to correctly load and access the plug-in resources in the installed plug-in;

[0010] The target Android native component in the post-installation plug-in is started, and communication between the post-installation plug-in and the host application is established.

[0011] By adopting the above technical solution, in the case of cold start of the host application, if it is determined that the locally installed plug-in of the host application needs to be upgraded, the plug-in package corresponding to the new version of the plug-in is dynamically obtained from the server and installed locally, and the plug-in of the host application is independently upgraded. Further, the classes in the plug-in after installation are loaded by a custom class loader, so that the host application can dynamically load the classes in the plug-in after installation without modifying the package of the host application itself, that is, the host project does not need to be updated as a whole. Then, in order to ensure the normal use of the functions after the plug-in upgrade, the plug-in resources are loaded through the custom AssetManager and the custom Resources object, so as to ensure that the resources in the plug-in after installation can be correctly loaded and accessed, and avoid resource conflicts of the host application. Finally, the target Android native component in the plug-in after installation is started, and the communication between the plug-in after installation and the host application is established, so that the plug-in after installation can support the Android native component, and the plug-in after installation can normally collaborate in data and functions with the host application, so that the overall update of the host project is not required while ensuring the normal use of the functions after the plug-in upgrade, reducing the frequent release of the host project and improving the efficiency of application development.

[0012] Optionally, obtaining a plug-in package corresponding to the new version plug-in from a server corresponding to the host application specifically includes:

[0013] Sending a plug-in upgrade request to the server corresponding to the host application;

[0014] Based on the plug-in upgrade request, receiving a download address of a new version of the plug-in sent by the server;

[0015] According to the download address, the plug-in package corresponding to the new version plug-in is downloaded from the server.

[0016] By adopting the above technical solution, a plug-in upgrade request is sent to the server corresponding to the host application, indicating that there is a need to upgrade the plug-in inside the host application. The host application sends the download address of the new version of the plug-in based on the plug-in upgrade request, and finally realizes the dynamic update of the plug-in. Compared with the traditional static management of plug-ins, the dynamic update of plug-ins can update and upgrade the plug-in without upgrading the host project.

[0017] Optionally, the target Android native component is divided into a target Activity component, a target Service component, a target BroadcastReceiver component and a target ContentProvider component, and starting the target Android native component in the installed plug-in specifically includes:

[0018] When the target Android native component is a target Activity component, based on the Hook technology, the normal startup process of the system Activity component in the Android system is intercepted;

[0019] If the normal startup process of the system Activity component is intercepted, the permission check is performed through the pit-occupying Activity component, and when the permission check passes, the target Activity component in the installed plug-in is started;

[0020] When the target Android native component is a target Service component, Pservice is predefined in the AndroidManifest.xml of the host application, and the call of the system Service component in the Android system is intercepted based on the Hook technology;

[0021] If the call of the system Service component is intercepted, the target Service component is dynamically created in Pservice and started;

[0022] When the target Android native components are a target BroadcastReceiver component and a target ContentProvider component, if the host application parses the manifest of the plug-in package, the static registration state of the target BroadcastReceiver component and the target ContentProvider component is converted into a dynamic registration state.

[0023] By adopting the above technical solution, if the normal startup process of the system Activity component is intercepted, it means that the host application is starting the screen or interface, then the preset pit-occupying Activity component is used for permission verification, so as to ensure that the host application can use the required permissions normally in subsequent operations, avoiding functional abnormalities caused by permission problems. After the permission verification is passed, it means that the required permissions are available, and the target Activity component in the installed plug-in can be started and displayed normally, thereby ensuring a smooth transition of the host application interface; if the call of the system Service component is intercepted, the target Service component is dynamically created in Pservice, and this target Service component is started, thereby providing the installed plug-in with the ability to run services in the background for a long time; the static registration state of the target BroadcastReceiver component and the target ContentProvider component is converted to a dynamic registration state, thereby allowing the installed plug-in to dynamically register broadcast receivers and content providers, enhancing the communication capabilities between the installed plug-in and the host application, and ultimately enabling the installed plug-in to support Android native components, ensuring that the installed plug-in can achieve basic functions such as interface display, background services, broadcast reception and data sharing.

[0024] Optionally, the establishing communication between the post-installation plug-in and the host application specifically includes:

[0025] Establishing communication between the installed plug-in and the host application based on a first communication mechanism between the plug-in inside the host application and the host application;

[0026] Based on a second communication mechanism from the host application to the plug-in inside the host application, communication from the host application to the installed plug-in is established.

[0027] By adopting the above technical solution, through the pre-established first communication mechanism and the second communication mechanism, when the host application is cold started and the plug-in is dynamically sent to the host application, the communication between the host application and the installed plug-in and the communication between the installed plug-in and the host application can be established respectively, so that the two can communicate with each other conveniently and realize data exchange and functional collaboration.

[0028] Optionally, the establishing of communication from the installed plug-in to the host application based on the first communication mechanism from the plug-in inside the host application to the host application specifically includes:

[0029] Based on the interface provided by the host application, sending a method call request through the post-installation plug-in;

[0030] According to the method object name in the method call request, a corresponding target method object instance is screened from the method object instances registered by the host application, wherein the method object instance is an instance of an object encapsulated by a method declared in the host application;

[0031] Based on the method corresponding to the target method object instance, communication from the installed plug-in to the host application is established.

[0032] By adopting the above technical solution, the installed plug-in sends the method call request to the host application through the interface provided by the host application, so that the host application can filter the method that can communicate with the installed plug-in from the registered method object instances according to the method object name, that is, the target method object instance. Finally, the target method object instance is called, that is, the method declared by the target method object instance is called to execute the expected logic, and the communication from the installed plug-in to the host application is established, thereby increasing the flexibility of communication.

[0033] Optionally, the establishing of communication between the host application and the installed plug-in based on the second communication mechanism between the host application and the plug-in inside the host application specifically includes:

[0034] Determine the Module class corresponding to the installed plug-in, where the Module class inherits from the IModule interface;

[0035] Based on the reflection mechanism, obtain the target instance of the Module class corresponding to the installed plug-in;

[0036] Get the corresponding Binder instance through the getBinder method in the target instance;

[0037] The method declared in the post-installation plug-in is called according to the Binder instance, and communication between the host application and the post-installation plug-in is established through the IModule interface.

[0038] By adopting the above technical solution, the Module class corresponding to the installed plug-in is determined, so that the host application and the installed plug-in can be logically decoupled through the IModule interface, enhancing flexibility and maintainability. Further, through the reflection mechanism, the host application is allowed to dynamically obtain the instance of the Module class of the installed plug-in, that is, the target instance, without static dependence, so as to simply and quickly obtain the corresponding Binder instance, and then more easily call the method declared in the installed plug-in, and rely on the IModule interface as a unified communication interface, so as to facilitate the communication between the host application and the installed plug-in.

[0039] Optionally, before loading the class in the installed plug-in by a preset custom class loader, the method further includes:

[0040] Based on a preset class loader hierarchy relationship, a custom class loader is determined, wherein the custom class loader includes a PluginClassLoader instance for loading classes in different types of plug-ins in the host application;

[0041] Based on reflection technology, the system class loader in the Android system is replaced with the custom class loader. The class loader hierarchical relationship includes a first parent-child relationship of the class loader and a second parent-child relationship of the class loader. The first parent-child relationship of the class loader is the parent-child relationship between the system class loader and the custom class loader, and the second parent-child relationship of the class loader is the parent-child relationship between the path class loader in the Android system and the system class loader.

[0042] By adopting the above technical solution, since the system class loader of the Android system cannot normally load the classes in the installed plug-in, based on the class loader hierarchy relationship, it is determined that the classes in different types of plug-ins in the host application can be loaded, and the system class loader is replaced with a custom class loader, so that the classes in the installed plug-in in the host application can be accurately and successfully loaded through the custom class loader.

[0043] In a second aspect of the present application, an Android-based application plug-in device is provided, specifically comprising:

[0044] An upgrade judgment module, used to judge whether the locally installed plug-in of the host application needs to be upgraded when the host application is cold started;

[0045] A plug-in installation module, for obtaining a plug-in package corresponding to the new version of the plug-in from the server corresponding to the host application, and installing it locally to obtain an installed plug-in;

[0046] A plug-in loading module, used to load classes in the installed plug-in through a preset custom class loader, wherein the custom class loader is used to load classes in different types of plug-ins in the host application;

[0047] A resource loading module, used to load the plug-in resources in the installed plug-in through a preset custom AssetManager and a custom Resources object, wherein the custom AssetManager and the custom Resources object are used to correctly load and access the plug-in resources in the installed plug-in;

[0048] The communication establishment module is used to start the target Android native component in the post-installation plug-in and establish communication between the post-installation plug-in and the host application.

[0049] By adopting the above technical solution, the upgrade judgment module determines whether the locally installed plug-in needs to be upgraded. When an upgrade is required, the plug-in installation module installs the plug-in package. Then the plug-in loading module loads the type in the installed plug-in. The resource loading module loads the plug-in resources in the installed plug-in. Finally, the communication establishment module establishes communication between the installed plug-in and the host application.

[0050] In a third aspect of the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is loaded and executed by a processor, the method steps described in any one of the first aspects are performed.

[0051] In a fourth aspect of the present application, an electronic device is provided, specifically comprising:

[0052] A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the processor is used to load and execute the computer program stored in the memory so that the electronic device performs the method as described in any one of the first aspects.

[0053] In summary, the present application includes at least one of the following beneficial technical effects: by loading the classes in the installed plug-in through a custom class loader, the host application can dynamically load the classes in the installed plug-in without modifying the program package of the host application itself, that is, the host project does not need to be updated as a whole. Then, in order to ensure the normal use of the functions after the plug-in upgrade, the plug-in resources are loaded through the custom AssetManager and the custom Resources object, so as to ensure that the resources in the installed plug-in can be correctly loaded and accessed, and avoid resource conflicts of the host application. Finally, the target Android native component in the installed plug-in is started, and the communication between the installed plug-in and the host application is established, so that the installed plug-in can support the Android native component, and the installed plug-in and the host application can normally perform data collaboration and function collaboration, so that the plug-in can be independently upgraded by issuing the installed plug-in while ensuring the normal use of the functions after the plug-in upgrade, without the need to update the host project as a whole, reducing the frequent release of the host project and improving the efficiency of application development. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 This is a flow chart of an Android-based application plug-in method provided in an embodiment of the present application;

[0055] Figure 2It is a flowchart of another Android-based application plug-in method provided in an embodiment of the present application;

[0056] Figure 3 This is a structural diagram of an Android-based application plug-in device provided in an embodiment of the present application;

[0057] Figure 4 It is a structural diagram of another Android-based application plug-in device provided in an embodiment of the present application.

[0058] Explanation of the accompanying drawings: 11. Upgrade judgment module; 12. Plug-in installation module; 13. Plug-in loading module; 14. Resource loading module; 15. Communication establishment module; 16. Object replacement module. DETAILED DESCRIPTION

[0059] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.

[0060] In the description of the embodiments of the present application, words such as "illustrative", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "illustrative", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "illustrative", "for example" or "for example" is intended to present related concepts in a concrete way.

[0061] In the description of the embodiments of the present application, the term "and / or" is only a kind of association relationship describing the associated objects, indicating that there may be three kinds of relationships, for example, A and / or B, which can represent: A exists alone, B exists alone, and A and B exist at the same time. In addition, unless otherwise specified, the meaning of the term "multiple" refers to two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" can explicitly or implicitly include one or more of the features. The terms "include", "comprise", "have" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.

[0062] See also Figure 1The present application embodiment discloses a flow chart of an Android-based application plug-in method, which can be implemented by a computer program or run on an Android-based application plug-in device based on the von Neumann system. The computer program can be integrated into an application or run as an independent tool application, specifically including:

[0063] S101: When the host application is cold started, determine whether a locally installed plug-in of the host application needs to be upgraded.

[0064] Specifically, the host application refers to an application or application software with which the internal plug-in or plug-in module interacts. The host application provides the environment and resources required for the operation of the internal plug-in, and is responsible for managing and calling the services provided by the plug-in. In an embodiment of the present application, the execution subject of an Android-based application plug-in method disclosed in an embodiment of the present application is a terminal. The terminal can be a smartphone or personal computer of a user of the host application, and the terminal has the host application installed. In addition, a cold start refers to a host application that is completely closed, that is, when there is no process of the host application in the background, a new process is created to start the host application. Among them, a locally installed plug-in refers to a plug-in that has been installed and can be used in the host application.

[0065] Furthermore, the preset Profiler tool is used to determine whether the host application on the terminal is cold started. In the case of a cold start of the host application, it is necessary to determine whether the locally installed plug-in of the host application needs to be upgraded. A feasible judgment method is to call the interface (Application Programming Interface, API) provided by the server corresponding to the host application. In the embodiment of the present application, the interface is a Representational State Transfer (REST) ​​interface. Among them, the server refers to the back-end system that provides data storage, data processing and other servers for the host application of the terminal. It usually runs on the server. The server can be an independent physical server or a server cluster or distributed system composed of multiple physical servers. Then, the version information of the locally installed plug-in is sent to the server through the interface. After the server receives the version information, if there is a version higher than this version information in the configuration file, then the server receives the response sent by the server that needs to be upgraded, and determines that the locally installed plug-in of the host application needs to be upgraded; otherwise, it is determined that the locally installed plug-in does not need to be upgraded.

[0066] S102: If yes, obtain the plug-in package corresponding to the new version plug-in from the server corresponding to the host application, and install it locally to obtain the installed plug-in.

[0067] Specifically, if it is determined that the locally installed plug-in needs to be upgraded, then the plug-in package corresponding to the new version of the plug-in is obtained from the server corresponding to the host application. The new version of the plug-in refers to the updated functional plug-in. The plug-in package (Android Application Package, APK) refers to an independent APK file that can be loaded and run when the application that supports plug-in, that is, the host application, is running. A feasible way to obtain the plug-in package is: send a plug-in upgrade request to the server corresponding to the host application; based on the plug-in upgrade request, receive the download address of the new version of the plug-in sent by the server; according to the download address, download the plug-in package corresponding to the new version of the plug-in from the server.

[0068] Specifically, the terminal sends a plug-in upgrade request to the server corresponding to the host application, and specifically sends it through the interface provided by the server. After receiving the plug-in upgrade request sent by the terminal, the server generates a corresponding download address based on the plug-in package of the new version of the plug-in preset in the server through the preset packaging tool VasDolly tool. Finally, the server returns the new version of the plug-in, that is, the download address of the plug-in package of the new version of the plug-in. The terminal receives the download address sent by the server, automatically downloads the plug-in package according to the download address, and finally automatically performs local automatic installation of the terminal to obtain the installed plug-in. It should be noted that a feasible way to determine the plug-in package is: the server downloads the new version of the plug-in according to the download link of the new version of the plug-in provided by the developer, and then modifies the version number of the new version of the plug-in according to the plug-in version number rule. The plug-in version number rule is: the plug-in version number is composed of six digits at the end, the first three digits represent the minimum supported host application version number, and the last three digits represent the plug-in version number. When the plug-in is updated, the last three digits are increased by 1 to identify the new version of the plug-in. Finally, the plug-in package corresponding to the new version of the plug-in is built by executing the build command gradle clean assembleDebug command.

[0069] S103: Loading classes in the installed plug-in through a preset custom class loader, where the custom class loader is used to load classes in different types of plug-ins in the host application.

[0070] In an achievable implementation, before step S103, the method further includes: determining a custom class loader based on a preset class loader hierarchy relationship, where the custom class loader includes a PluginClassLoader instance for loading classes in different types of plug-ins in the host application;

[0071] Based on reflection technology, the system class loader in the Android system is replaced with a custom class loader.

[0072] Specifically, after the plug-in is installed, the host application is not fully upgraded. The host application needs to be able to dynamically load the classes in the plug-in after installation to avoid modifying the APK of the host application, which is a key step in realizing plug-inization. Then it is necessary to load the classes in the plug-in after installation normally through a custom class loader determined in advance. The custom class loader is used to load classes in different types of plug-ins in the host application. The main reason is that the system class loader of the Android system on which the host application depends cannot load the classes in the plug-in after installation normally. Among them, the system class loader (ClassLoader), that is, BootClassLoader, is the parent class of all other class loaders and is responsible for loading the core library of the Android system. Further, based on the preset class loader hierarchy, several PluginClassLoader instances that can load classes in different types of plug-ins in the host application are created, and a custom class loader is obtained by jointly forming several PluginClassLoader instances. Among them, the PluginClassLoader instance refers to a class loader object that can load classes in plug-ins of different types, and can also load classes in plug-ins after installation. In addition, the class in the plug-in refers to the Java class or Kotlin class in the plug-in module that is split out and packaged separately in the application plug-in development under the Android system. It should be noted that the class loader hierarchy relationship includes the first parent-child relationship of the class loader and the second parent-child relationship of the class loader. The first parent-child relationship of the class loader is the parent-child relationship between the system class loader and the custom class loader, that is, the system class loader is the parent class of the custom class loader. The second parent-child relationship of the class loader is the parent-child relationship between the path class loader and the system class loader in the Android system, that is, the path class loader is the parent class of the system class loader. Path class loader (PathClassLoader) refers to a standard class loader in the Android system. It inherits from the BaseDexClassLoader class and is used to load classes and resources from a specified path.

[0073] Furthermore, through reflection technology, the system class loader in the Android system is replaced with a custom class loader, so that the host application can normally load the classes in the installed plug-in, thereby realizing the dynamic update of the host application and providing a flexible and secure application running environment. Reflection technology refers to a key feature in the Java language, which allows the program to introspect and modify its own structure and behavior at runtime.

[0074] S104: Load the plug-in resources in the installed plug-in through the preset custom AssetManager and custom Resources objects. The custom AssetManager and custom Resources objects are used to correctly load and access the plug-in resources in the installed plug-in.

[0075] Specifically, after the class loading in the installed plug-in is completed, since the installed plug-in also includes the plug-in resources corresponding to the new version of the plug-in, the plug-in resources refer to the non-code files contained in the new version of the plug-in, such as pictures, layout files, string definitions, etc. Therefore, in order to ensure that the corresponding new functions can be used normally after the plug-in is upgraded, the plug-in resources in the installed plug-in are loaded through the preset custom AssetManager and custom Resources object, so that the plug-in resources in the installed plug-in can be normally loaded and accessed by the host application, and then the new functions corresponding to the new version of the plug-in can be used normally. Among them, in the embodiment of the present application, the custom AssetManager is mainly used to access the files in the assets directory corresponding to the plug-in resources in the host application, and the custom Resources object is the core class used to access plug-in resources in the Android system.

[0076] Furthermore, before step S104, a custom AssetManager is created. One feasible way to create it is to inherit the android.content.res.AssetManager class and implement the methods therein. Then, a custom Resources object is created based on the custom AssetManager. The specific creation process is: use the Resources.getSystem() method to obtain the system default Resources object, and then call the newResources(AssetManager) method to pass it into the custom AssetManage, and finally obtain the custom Resources object. Finally, through reflection technology, replace the mResources in PackageInfo in the Android system with this custom Resources object. Among them, PackageInfo is a class in the Android system, which contains information about the application package, including the name, version number, permissions, etc. of the application. The mResources field is a reference to the application resource object.

[0077] S105: Start the target Android native component in the post-installation plug-in, and establish communication between the post-installation plug-in and the host application.

[0078] Specifically, after the plugin resources in the installed plugin are loaded, the target Android native component in the installed plugin is started, so that the plug-in application, that is, the host application, can seamlessly integrate and utilize the core native components in the Android system, that is, install the native components, and then achieve a functional experience similar to that of the native application (non-plug-in application). In the embodiment of the present application, Android native components are generally divided into four, namely, the system activity (Activity) component, the system service (Service) component, the system broadcast receiver (BroadcastReceiver) component and the system content provider (ContentProvider) component. The target Android native component is divided into a target Activity component, a target Service component, a target BroadcastReceiver component and a target ContentProvider component.

[0079] Further, when the target Android native component is the target Activity component, the Hook technology is used to intercept the normal startup process of the system Activity component in the Android system, wherein the Hook technology is also called a hook function, which allows the application to set a subroutine to monitor a certain message of the specified window, and is usually used to intercept and process system calls, function calls and other events. The system Activity component is a core component in the Android application, which is responsible for handling the user interface and user interaction. If it is successfully intercepted, it means that the host application is starting a certain screen or interface, then the preset pit-occupying Activity component is used for permission verification, so as to ensure that the host application can use the required permissions normally in subsequent operations, and avoid functional abnormalities caused by permission problems, wherein the pit-occupying Activity component refers to the Activity used for placeholders in the host application, which is usually created when the application is started, to ensure that the host application can start normally. After the permission verification is passed, it means that the required permissions are obtained, and the target Activity component in the installed plug-in can be started and displayed normally, thereby ensuring a smooth transition of the interface of the host application. It should be noted that the target Activity component is obtained by the host application loading the Activity class in the installed plug-in through a custom class loader.

[0080] Further, when the target Android native component is the target Service component, that is, it is necessary to start the target Service component in the installed plug-in to achieve the effect of executing the corresponding application function in the background. Service is a background component that can perform long-running operations or network transactions in the background without providing a user interface. Further, Pservice is predefined in the AndroidManifest.xml of the host application, thereby declaring that a Service component is provided in the installed plug-in, without explicitly declaring it in the AndroidManifest.xml of the host application, and then intercepting the call of the system Service component in the Android system through the Hook technology. For example, intercepting the call of startService, stopService, etc., if the call of the system Service component is intercepted, the system Service component refers to a component used to perform long-running background operations in the Android system. Dynamically create a target Service component in Pservice, and start this target Service component, so as to provide the installed plug-in with the ability to run services in the background for a long time. Among them, a feasible way to create a target Service component is to obtain it by loading the Service class in the installed plug-in through a custom class loader. In addition, AndroidManifest.xml is a configuration file that must be included in every Android application. It describes the application's basic properties, components (such as activities, services, broadcast receivers, and content providers), and required permissions.

[0081] Furthermore, when the target Android native components are the target BroadcastReceiver component and the target ContentProvider component, it is determined whether the host application parses the manifest of the plug-in package, wherein parsing the manifest of the plug-in package refers to reading and analyzing the AndroidManifest.xml file in the plug-in package. If the host application parses the manifest of the plug-in package, the static registration state of the target BroadcastReceiver component and the target ContentProvider component is converted to a dynamic registration state, thereby allowing the plug-in to dynamically register the broadcast receiver and the content provider after installation, thereby enhancing the communication capability between the plug-in and the host application after installation. It should be noted that the target BroadcastReceiver component and the target ContentProvider component are obtained by loading the BroadcastReceiver class and the ContentProvider class in the plug-in after installation through a custom class loader. Ultimately, the plug-in after installation can support Android native components, ensuring that the plug-in after installation can achieve some basic functions, such as interface display, background service, broadcast reception and data sharing.

[0082] Furthermore, communication is established between the post-installation plug-in and the host application, so that the post-installation plug-in can interact smoothly with the host application, ensuring the overall stability and scalability of the host application. A feasible way to establish communication is to establish communication between the post-installation plug-in and the host application through the open source event bus (EventBus), wherein EventBus is a publish / subscribe event bus optimized for Android, which can define specific event types (i.e., message classes) and register as subscribers and publishers of the event in the post-installation plug-in and the host application, respectively. When the post-installation plug-in needs to send a message to the host application, it can publish an event; and the subscriber in the host application will receive this event and perform corresponding processing, and finally establish communication. This is a prior art and will not be repeated here.

[0083] See also Figure 2 The present application embodiment discloses a flowchart of another method for plug-in application based on Android, which can be implemented by a computer program and can also be run on an Android-based plug-in application device based on the von Neumann system. The computer program can be integrated into the application or run as an independent tool application, specifically including:

[0084] S201: When the host application is cold started, determine whether a locally installed plug-in of the host application needs to be upgraded.

[0085] S202: If yes, obtain the plug-in package corresponding to the new version plug-in from the server corresponding to the host application, and install it locally to obtain the installed plug-in.

[0086] S203: Loading classes in the installed plug-in through a preset custom class loader, where the custom class loader is used to load classes in different types of plug-ins in the host application.

[0087] S204: Load the plug-in resources in the installed plug-in through the preset custom AssetManager and custom Resources objects. The custom AssetManager and custom Resources objects are used to correctly load and access the plug-in resources in the installed plug-in.

[0088] For details, please refer to steps S101-S104, which will not be described in detail here.

[0089] S205: Start the target Android native component in the post-installation plug-in, and establish communication from the post-installation plug-in to the host application based on the first communication mechanism from the plug-in to the host application inside the host application.

[0090] Specifically, start the target Android native component in the post-installation plug-in, see step S105 for details. Further, establish the communication between this post-installation plug-in and the host application. A feasible implementation method is: call the interface provided by the host application, and the post-installation plug-in sends a method call request to the host application. The method call request is mainly used to request the host application to call a registered method object instance. In the embodiment of the present application, the method object instance refers to the instance of the object encapsulated by the method declared in the host application. Further, the method declared in the host application is classified according to whether it accepts parameters and whether it has a return value. The classification is as follows: four method types: methods with parameters and return values, methods with parameters but no return values, methods without parameters and no return values, and methods without parameters and return values. Among them, four different types of methods are encapsulated into objects to obtain four different method objects, which are easy to manage and maintain. At the same time, according to the predefined communication protocol, the instances of these four method objects are registered, and finally the registered method object instances are obtained.

[0091] It should be noted that "with parameters and return values" means that the plug-in passes parameters to the method declared in the host application, and the host application returns the return value to the plug-in. "with parameters but no return value" means that the plug-in passes parameters to the method declared in the host application, and the host application does not return the return value to the plug-in; "without parameters and no return value" means that when the plug-in calls the method declared in the host application, there is no need to pass parameters, and the host application does not return the return value to the plug-in; "without parameters and return value" means that when the plug-in calls the method declared in the host application, there is no need to pass parameters, and the host application needs to return the return value to the plug-in.

[0092] Furthermore, the method call request is parsed to obtain the method object name contained therein, and then the corresponding target method object instance is filtered out from each registered method object instance according to the method object name. Finally, the host application calls the method corresponding to this target method object instance, thereby ultimately establishing communication from the installed plug-in to the host application.

[0093] S206: Establish communication from the host application to the installed plug-in based on the second communication mechanism from the host application to the plug-in inside the host application.

[0094] Specifically, after establishing the communication from the installed plug-in to the host application, it is necessary to further establish the communication from the host application to the installed plug-in. A feasible implementation method is as follows: first, define the Module class corresponding to the installed plug-in. The package names of the Module class are named according to a preset fixed format, so that the host application can quickly and accurately find the Module class corresponding to the installed plug-in. The Module class inherits from the IModule interface, which is a unified communication interface between the host application and the plug-in. Through this IModule interface, the logical decoupling between the host application and the installed plug-in can be achieved, and the flexibility and maintainability can be enhanced. Among them, the Module class usually refers to a specific implementation class, which can implement the interface or specification defined by the plug-in. In other words, the Module class provides the specific implementation of all methods declared by the IModule interface. Furthermore, through reflection technology, the instance of the Module class corresponding to the installed plug-in, that is, the target instance, is obtained, wherein the target instance is a specific object created according to the definition of the Module class. Then the host application calls the getBinder method in the target instance. The getBinder method is used to return the Binder instance to the host application. The Binder instance usually refers to an object used to implement inter-process communication (IPC), which allows different processes to call methods and transfer data to each other. Finally, the host application uses this Binder instance to remotely call the method declared in the installed plug-in, and uses the IModule interface corresponding to the installed plug-in as the communication interface to establish communication interaction between the host application and the plug-in. Among them, the method declared in the installed plug-in refers to the interface that the installed plug-in exposes to the host application in order to allow the installed plug-in to communicate with the host application.

[0095] The implementation principle of the application plug-in method based on Android in the embodiment of the present application is: the classes in the plug-in after installation are loaded through a custom class loader, so that the host application can dynamically load the classes in the plug-in after installation without modifying the program package of the host application itself, that is, the host project does not need to be updated as a whole. Then, in order to ensure the normal use of the functions after the plug-in upgrade, the plug-in resources are loaded through the custom AssetManager and the custom Resources object, so as to ensure that the resources in the plug-in after installation can be correctly loaded and accessed, and avoid resource conflicts of the host application. Finally, the target Android native component in the plug-in after installation is started, and the communication between the plug-in after installation and the host application is established, so that the plug-in after installation can support the Android native component, and the plug-in after installation can normally collaborate in data and functions with the host application, so that the plug-in can be independently upgraded by issuing the plug-in after installation, without the need to update the host project as a whole, reducing the frequent release of the host project and improving the efficiency of application development.

[0096] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0097] See also Figure 3 , which is a schematic diagram of the structure of an application plug-in device based on Android provided in an embodiment of the present application. The application plug-in device based on Android can be implemented as all or part of the device through software, hardware or a combination of both. The device includes an upgrade judgment module 11, a plug-in installation module 12, a plug-in loading module 13, a resource loading module 14 and a communication establishment module 15.

[0098] The upgrade judgment module 11 is used to judge whether the locally installed plug-in of the host application needs to be upgraded when the host application is cold started;

[0099] The plug-in installation module 12 is used to obtain the plug-in package corresponding to the new version plug-in from the server corresponding to the host application, and install it locally to obtain the installed plug-in;

[0100] A plug-in loading module 13 is used to load classes in the installed plug-in through a preset custom class loader, and the custom class loader is used to load classes in different types of plug-ins in the host application;

[0101] The resource loading module 14 is used to load the plug-in resources in the installed plug-in through the preset custom AssetManager and custom Resources object. The custom AssetManager and custom Resources object are used to correctly load and access the plug-in resources in the installed plug-in;

[0102] The communication establishing module 15 is used to start the target Android native component in the post-installation plug-in and establish the communication between the post-installation plug-in and the host application.

[0103] Optionally, the plug-in installation module 12 is specifically used for:

[0104] Send a plug-in upgrade request to the server corresponding to the host application;

[0105] Based on the plug-in upgrade request, receive the download address of the new version of the plug-in sent by the server;

[0106] Download the plug-in package corresponding to the new version of the plug-in from the server according to the download address.

[0107] Optionally, the communication establishment module 15 is specifically used for:

[0108] When the target Android native component is the target Activity component, the normal startup process of the system Activity component in the Android system is intercepted based on the Hook technology;

[0109] If the normal startup process of the system Activity component is intercepted, the permission check is performed through the pit-occupying Activity component, and when the permission check passes, the target Activity component in the installed plug-in is started;

[0110] When the target Android native component is the target Service component, Pservice is predefined in the AndroidManifest.xml of the host application, and the call of the system Service component in the Android system is intercepted based on the Hook technology;

[0111] If the call of the system Service component is intercepted, the target Service component is dynamically created in Pservice and started;

[0112] When the target Android native components are the target BroadcastReceiver component and the target ContentProvider component, if the host application parses the manifest of the plug-in package, the static registration state of the target BroadcastReceiver component and the target ContentProvider component is converted to a dynamic registration state.

[0113] Optionally, the communication establishment module 15 is specifically used for:

[0114] Establishing communication from the installed plug-in to the host application based on a first communication mechanism from the plug-in to the host application within the host application;

[0115] Based on the second communication mechanism from the host application to the plug-in inside the host application, communication from the host application to the installed plug-in is established.

[0116] Optionally, the communication establishment module 15 is specifically used for:

[0117] Send method call requests through installed plugins based on the interface provided by the host application;

[0118] According to the communication method object name in the method call request, the corresponding target method object instance is screened out from the method object instances registered by the host application, where the method object instance is an instance of an object encapsulated by the method declared in the host application;

[0119] Establish communication from the installed plugin to the host application based on the method corresponding to the target method object instance.

[0120] Optionally, the communication establishment module 15 is specifically used for:

[0121] Determine the Module class corresponding to the installed plug-in. The Module class inherits from the IModule interface.

[0122] Based on the reflection mechanism, obtain the target instance of the Module class corresponding to the installed plug-in;

[0123] Get the corresponding Binder instance through the getBinder method in the target instance;

[0124] Call the method declared in the installed plug-in according to the Binder instance, and establish communication from the host application to the installed plug-in through the IModule interface.

[0125] Optional, such as Figure 4 As shown, the device also includes an object replacement module 16, which is specifically used to:

[0126] Based on the preset class loader hierarchy, a custom class loader is determined. The custom class loader includes PluginClassLoader instances for loading classes in different types of plug-ins in the host application.

[0127] Based on reflection technology, the system class loader in the Android system is replaced with a custom class loader. The class loader hierarchical relationship includes the class loader first parent-child relationship and the class loader second parent-child relationship. The class loader first parent-child relationship is the parent-child relationship between the system class loader and the custom class loader, and the class loader second parent-child relationship is the parent-child relationship between the path class loader and the system class loader in the Android system.

[0128] It should be noted that the Android-based application plug-in device provided in the above embodiment only uses the division of the above functional modules as an example when executing the Android-based application plug-in method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the Android-based application plug-in device and the Android-based application plug-in method embodiment provided in the above embodiment belong to the same concept. The implementation process is detailed in the method embodiment and will not be repeated here.

[0129] An embodiment of the present application further discloses a computer-readable storage medium, and the computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, an Android-based application plug-in method of the above embodiment is adopted.

[0130] Among them, the computer program can be stored in a computer-readable medium, the computer program includes computer program code, the computer program code can be in the form of source code, object code, executable file or certain middleware, etc. The computer-readable medium includes any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the computer-readable medium includes but is not limited to the above-mentioned components.

[0131] Among them, through this computer-readable storage medium, an Android-based application plug-in method of the above embodiment is stored in a computer-readable storage medium, and is loaded and executed on a processor to facilitate the storage and application of the above method.

[0132] An embodiment of the present application further discloses an electronic device, in which a computer program is stored in a computer-readable storage medium. When the computer program is loaded and executed by a processor, the above-mentioned Android-based application plug-in method is adopted.

[0133] The electronic device may be a desktop computer, a laptop computer, a cloud server or other electronic device, and the electronic device includes but is not limited to a processor and a memory. For example, the electronic device may also include input and output devices, a network access device, and a bus.

[0134] Among them, the processor can adopt a central processing unit (CPU). Of course, according to actual usage, other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. can also be adopted. The general-purpose processor can adopt a microprocessor or any conventional processor, etc., and this application does not impose any restrictions on this.

[0135] Among them, the memory can be an internal storage unit of the electronic device, such as a hard disk or memory of the electronic device, or it can be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (SMC), a secure digital card (SD) or a flash memory card (FC) equipped on the electronic device. Moreover, the memory can also be a combination of an internal storage unit and an external storage device of the electronic device. The memory is used to store computer programs and other programs and data required by the electronic device. The memory can also be used to temporarily store data that has been output or is to be output, and this application does not impose any restrictions on this.

[0136] Among them, through this electronic device, an Android-based application plug-in method of the above embodiment is stored in the memory of the electronic device, and is loaded and executed on the processor of the electronic device for easy use.

[0137] The above is only an exemplary embodiment of the present disclosure, and the scope of the present disclosure cannot be limited thereto. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the specification and practicing the disclosure here, those skilled in the art will easily think of other embodiments of the present disclosure. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the technical field not recorded in the present disclosure. The description and examples are only regarded as exemplary, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. An application plug-in method based on Android, characterized in that: The method comprises: In the case of a cold start of the host application, determining whether a locally installed plug-in of the host application needs to be upgraded; If so, obtain the plug-in package corresponding to the new version of the plug-in from the server corresponding to the host application, and install it locally to obtain the installed plug-in; Loading classes in the installed plug-in through a preset custom class loader, wherein the custom class loader is used to load classes in different types of plug-ins in the host application; Load the plug-in resources in the installed plug-in through the preset custom AssetManager and custom Resources object, wherein the custom AssetManager and the custom Resources object are used to correctly load and access the plug-in resources in the installed plug-in; The target Android native component in the post-installation plug-in is started, and communication between the post-installation plug-in and the host application is established, wherein the target Android native component is divided into a target Activity component, a target Service component, a target BroadcastReceiver component, and a target ContentProvider component. The starting of the target Android native component in the post-installation plug-in specifically includes: When the target Android native component is a target Activity component, based on the Hook technology, the normal startup process of the system Activity component in the Android system is intercepted; If the normal startup process of the system Activity component is intercepted, the permission check is performed through the pit-occupying Activity component, and when the permission check passes, the target Activity component in the installed plug-in is started; When the target Android native component is a target Service component, Pservice is predefined in the AndroidManifest.xml of the host application, and the call of the system Service component in the Android system is intercepted based on the Hook technology; If the call of the system Service component is intercepted, the target Service component is dynamically created in Pservice and started; When the target Android native components are a target BroadcastReceiver component and a target ContentProvider component, if the host application parses the manifest of the plug-in package, the static registration state of the target BroadcastReceiver component and the target ContentProvider component is converted to a dynamic registration state; The establishing of communication between the post-installation plug-in and the host application specifically includes: Establishing communication between the installed plug-in and the host application based on a first communication mechanism between the plug-in inside the host application and the host application; Establishing communication between the installed plug-in and the host application based on the first communication mechanism between the plug-in inside the host application and the host application specifically includes: Based on the interface provided by the host application, sending a method call request through the post-installation plug-in; According to the method object name in the method call request, a corresponding target method object instance is screened from the method object instances registered by the host application, wherein the method object instance is an instance of an object encapsulated by a method declared in the host application; Establishing communication from the installed plug-in to the host application based on the method corresponding to the target method object instance; Establishing communication between the host application and the installed plug-in based on the second communication mechanism between the host application and the plug-in inside the host application; Establishing communication between the host application and the installed plug-in based on the second communication mechanism between the host application and the plug-in inside the host application, specifically includes: Determine the Module class corresponding to the installed plug-in, where the Module class inherits from the IModule interface; Based on the reflection mechanism, obtain the target instance of the Module class corresponding to the installed plug-in; Get the corresponding Binder instance through the getBinder method in the target instance; The method declared in the post-installation plug-in is called according to the Binder instance, and communication between the host application and the post-installation plug-in is established through the IModule interface.

2. The Android-based application plug-in method according to claim 1, characterized in that: The step of obtaining a plug-in package corresponding to the new version plug-in from the server corresponding to the host application specifically includes: Sending a plug-in upgrade request to the server corresponding to the host application; Based on the plug-in upgrade request, receiving a download address of a new version of the plug-in sent by the server; According to the download address, the plug-in package corresponding to the new version plug-in is downloaded from the server.

3. The Android-based application plug-in method according to claim 1, characterized in that: Before loading the class in the installed plug-in by the preset custom class loader, the method further includes: Based on a preset class loader hierarchy relationship, a custom class loader is determined, wherein the custom class loader includes a PluginClassLoader instance for loading classes in different types of plug-ins in the host application; Based on reflection technology, the system class loader in the Android system is replaced with the custom class loader. The class loader hierarchical relationship includes a first parent-child relationship of the class loader and a second parent-child relationship of the class loader. The first parent-child relationship of the class loader is the parent-child relationship between the system class loader and the custom class loader, and the second parent-child relationship of the class loader is the parent-child relationship between the path class loader in the Android system and the system class loader.

4. An Android-based application plug-in device, used to implement the Android-based application plug-in method according to any one of claims 1 to 3, characterized in that: include: An upgrade judgment module (11) is used to judge whether the locally installed plug-in of the host application needs to be upgraded when the host application is cold started; A plug-in installation module (12), for obtaining a plug-in package corresponding to the new version of the plug-in from a server corresponding to the host application, and installing it locally to obtain an installed plug-in; A plug-in loading module (13), used for loading classes in the installed plug-in through a preset custom class loader, wherein the custom class loader is used for loading classes in different types of plug-ins in the host application; A resource loading module (14), used to load the plug-in resources in the installed plug-in through a preset custom AssetManager and a custom Resources object, wherein the custom AssetManager and the custom Resources object are used to correctly load and access the plug-in resources in the installed plug-in; The communication establishment module (15) is used to start the target Android native component in the post-installation plug-in and establish communication between the post-installation plug-in and the host application.

5. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, characterized in that: When the computer program is loaded and executed by a processor, the method according to any one of claims 1 to 3 is adopted.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that: When the processor loads and executes the computer program, the method according to any one of claims 1 to 3 is adopted.

Citation Information

Patent Citations

  • Plug-in management method of application program of Android terminal

    CN107992308A

  • Application program loading method, application program loading device, medium and equipment

    CN112068903A