Android application hot update method based on plug-in framework, Android application system and computer readable medium

By splitting Android applications into host APK and sub-APK modules, and using the Hook system Instrumentation class to generate proxy classes, dynamically loading Dex files and resources in sub-APKs, the problem of low update efficiency in the existing technology is solved, and bugs or update functions are fixed without re-listing, which improves update efficiency and compatibility.

CN120215995APending Publication Date: 2025-06-27HONGCHENG TECH DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510375760.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-27
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

When existing Android applications fix serious bugs or update functions, they need to repackage and list the application market, resulting in users not being able to obtain the latest version in time, and the review time is required for listing, which affects the update efficiency.

Method used

Using the plug-in framework, the Android application hot update method is used to split the Android application into host APK and sub-APK modules, and the proxy class is generated through the Hook system Instrumentation class, dynamically load the Dex files and resources in the sub-APK, and bypass the Android system component verification to achieve bugs or update functions without re-listing.

Benefits of technology

It has achieved bug or update function without re-listing, improved update efficiency, optimized APK volume, enhanced compatibility, and has clear commercial and technical value.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120215995A_ABST
    Figure CN120215995A_ABST
Patent Text Reader

Abstract

The invention discloses an Android application hot update method based on a plug-in framework, an Android application system and a computer readable medium, relates to the technical field of computers, and is different from a traditional plug-in scheme that only module decoupling is concerned, a hot update process is embedded into the plug-in framework, and a Bug repairing or updating function can be realized without putting on a shelf again by dynamically replacing codes in a sub-APK (Android Package). Meanwhile, the system mInstrumentation field is replaced through reflection, the Activity starting process is dynamically intercepted, and the key problem that the plug-in Activity cannot pass system verification is solved. Compared with a traditional class loader scheme, the method is more direct and higher in compatibility. According to the method, the updating efficiency is improved, the APK volume is optimized, the compatibility is enhanced, and the method has clear commercial and technical values.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to an Android application hot update method, an Android application system, and a computer-readable medium based on a plug-in framework. Background Art

[0002] In today's digital age, Android applications have been widely popularized and deeply penetrated into all aspects of people's lives. Among the apps available on major app markets, modifying functions or fixing bugs is a frequent operation. However, every time a serious bug is fixed or an urgent requirement is met, the app needs to be repackaged and uploaded to the app market for users to update, and the uploading also requires a certain review time, resulting in users being unable to update to the latest version in a timely manner. Summary of the Invention

[0003] The purpose of the present invention is to provide an Android application hot update method, an Android application system, and a computer-readable medium based on a plug-in framework, which can achieve bug fixing or function updating without having to be re-uploaded, thus improving the processing efficiency.

[0004] Embodiments of the present invention are implemented as follows: An Android application hot update method based on a plug-in framework, which includes the following steps: S1. Split the Android application into a host APK and at least one sub-APK module, where the host APK contains core functions, and the sub-APK module contains plug-in functions or update codes that can be dynamically loaded; S2. Generate a proxy class ProxyInstrumentation in the host APK by hooking the system Instrumentation class, override the execStartActivity method, and replace the target Activity with StubActivity to bypass Android system component verification; S3. When the application starts, replace the mInstrumentation field of the host APK with a ProxyInstrumentation instance through reflection; S4. Dynamically load the Dex files and resources in the sub-APK, and intercept the Activity startup process through the message processing layer, replacing the target component in the Intent with the actual plug-in Activity.

[0005] Further, in other preferred embodiments of the present invention, the loading of the sub-APK module in step S1 is on-demand loading, including the following sub-steps: S1.1 When the user triggers a specific function, download the corresponding sub - APK file from the server; S1.2 Merge the Dex files in the sub - APK into the class loader of the host APK and parse its resource path.

[0006] Furthermore, in other preferred embodiments of the present invention, the specific implementation of the Hook system's Instrumentation class includes: Create a ProxyInstrumentation class that inherits from Instrumentation and override the execStartActivity method; In the execStartActivity method, replace the target Activity in the original Intent with StubActivity and store the original Activity information in the extra field of the Intent; Modify the mInstrumentation field of the Activity instance in the host APK to a ProxyInstrumentation object through reflection.

[0007] Furthermore, in other preferred embodiments of the present invention, the implementation of the message processing layer includes: Override the handleMessage method of the Handler.Callback interface to intercept messages of the LAUNCH_ACTIVITY type; Extract the original target Activity from the extra field of the message's Intent and replace StubActivity with the actual plugin Activity.

[0008] Furthermore, in other preferred embodiments of the present invention, the packaging method of the sub - APK module is independent compilation, and the components declared in its AndroidManifest.xml do not need to be pre - registered in the host APK.

[0009] Furthermore, in other preferred embodiments of the present invention, the hot - update process includes: When it is detected that the sub - APK version is updated, download the updated sub - APK file; Realize the dynamic update of the application function by replacing the Dex file and resources, without the need to repackage the host APK or upload the application to the app market.

[0010] An Android application system for implementing the above - mentioned Android application hot - update method based on a plugin framework, which includes: A host APK module for providing core functions and a dynamic loading framework; The plugin management module is responsible for the download, parsing, and resource injection of sub-APKs; The Hook proxy module includes the ProxyInstrumentation class and reflection replacement logic; The message interception module is used to rewrite Handler.Callback and replace the target component in the Intent.

[0011] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above Android application hot update method based on the plugin framework are implemented.

[0012] The beneficial effects of the embodiments of the present invention are: The embodiments of the present invention provide an Android application hot update method, an Android application system, and a computer-readable medium based on a plugin framework. Different from traditional plugin solutions that only focus on module decoupling, it embeds the hot update process into the plugin framework and realizes bug fixing or function updating without having to be re-listed by dynamically replacing the code in the sub-APK. At the same time, by reflecting and replacing the system mInstrumentation field, the Activity startup process is dynamically intercepted, solving the key problem that plugin Activities cannot pass system verification. This method is more direct and has higher compatibility than traditional class loader solutions. This method improves the update efficiency (bypassing the application market review), optimizes the APK size, and enhances compatibility, with clear commercial and technical value. Description of the Drawings

[0013] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the embodiments. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can be obtained based on these drawings without creative efforts.

[0014] Figure 1 Example code for implementing step S2 in an Android application hot update method based on a plugin framework provided by an embodiment of the present invention; Figure 2 Example code for implementing step S3 in an Android application hot update method based on a plugin framework provided by an embodiment of the present invention; Figure 3 Example code for implementing step S4 in an Android application hot update method based on a plugin framework provided by an embodiment of the present invention; Figure 4Example code for implementing hot update in an Android application hot update method based on a plug-in framework provided by an embodiment of the present invention. Detailed implementation manners

[0015] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention. Therefore, the detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention. Embodiment

[0016] This embodiment provides an Android application hot update method based on a plug-in framework, which includes the following steps: S1. Split the Android application into a host APK and at least one sub-APK module, where the host APK contains core functions, and the sub-APK module contains plug-in functions or updated code that can be dynamically loaded.

[0017] Further, the loading of the sub-APK module in step S1 is on-demand loading, including the following sub-steps: S1.1 When the user triggers a specific function, download the corresponding sub-APK file from the server; S1.2 Merge the Dex files in the sub-APK into the class loader of the host APK and parse its resource path.

[0018] Further, the packaging method of the sub-APK module is independent compilation, and the components declared in its AndroidManifest.xml do not need to be pre-registered in the host APK.

[0019] By modifying the program into a plug-in framework, separating the host APK from multiple sub-APK modules, and combining dynamic loading technology to achieve on-demand loading, the size of the host APK can be reduced and the memory occupancy can be lowered.

[0020] An Android application hot update method based on a plug-in framework provided by this embodiment further includes: S2. Generate a proxy class ProxyInstrumentation in the host APK by hooking the system Instrumentation class, override the execStartActivity method, and replace the target Activity with StubActivity to bypass the Android system component verification.

[0021] Directly hook the system Instrumentation class, and bypass the verification through the StubActivity proxy, without the need for process isolation or complex interface adaptation, improving the running efficiency and development convenience.

[0022] Specifically, the specific implementation of hooking the system Instrumentation class includes: Create a ProxyInstrumentation class that inherits from Instrumentation and override the execStartActivity method; In the execStartActivity method, replace the target Activity in the original Intent with StubActivity, and store the original Activity information in the extra field of the Intent.

[0023] Optionally, Figure 1 A feasible example code is shown to implement the above process, and the main content includes: 1) Create a placeholder Intent: new Intent(target, TextActivity.class) creates a new Intent, **with the target component being TextActivity** (i.e., the placeholder Activity, such as StubActivity).

[0024] It can bypass the Android system's legality verification of Activity components (for example: AMS checks whether the Activity is declared in the AndroidManifest.xml of the host APK).

[0025] 2) Save the original Intent: replaceIntent.putExtra(TextActivity.TARGET_COMPONENT, intent) stores the original Intent (containing information about the actual plugin Activity to be launched) as additional data (Extra) in replaceIntent. Here, TextActivity.TARGET_COMPONENT is a custom Extra key used to extract the original Intent later.

[0026] 3) Replace the Intent: intent = replaceIntent replaces the current Intent with replaceIntent which contains the placeholder Activity.

[0027] The purpose is to deceive the system into launching the placeholder Activity, but the actual target Activity information is hidden in the Extra.

[0028] An Android application hot update method based on a plugin framework provided in this embodiment further includes: S3. When the application starts, replace the mInstrumentation field of the host APK with a ProxyInstrumentation instance through reflection.

[0029] Optionally, Figure 2 A piece of feasible sample code is shown to implement the above process, and the main content includes: 1) Obtain the private field through reflection: Activity.class.getDeclaredField("mInstrumentation") obtains the private field mInstrumentation of the Activity class through reflection. mInstrumentation is the core class in the Android system that controls the Activity lifecycle and component launching (such as launching an Activity, handling Activity jumps, etc.).

[0030] 2) Modify the field access permission: mInstrumentationField.setAccessible(true) forcibly allows access to the private field (bypassing Java's access control check).

[0031] 3) Create a proxy object and replace: mInstrumentationField.get(activity) obtains the original Instrumentation instance of the current Activity.

[0032] new ProxyInstrumentation(originalInstrumentation) creates a custom proxy class ProxyInstrumentation (inheriting from Instrumentation and used to override system behavior).

[0033] mInstrumentationField.set(activity, new ProxyInstrumentation(...)) injects the proxy object into the current Activity to replace the original Instrumentation of the system.

[0034] A method for hot updating Android applications based on a plug-in framework provided in this embodiment further includes: S4. Dynamically load Dex files and resources in the sub-APK, and intercept the Activity startup process through the message processing layer, replacing the target component in the Intent with the actual plug-in Activity.

[0035] Further, the implementation of the message processing layer includes: Override the handleMessage method of the Handler.Callback interface to intercept messages of the LAUNCH_ACTIVITY type; Extract the original target Activity from the Intent extra field of the message and replace StubActivity with the actual plug-in Activity.

[0036] Optionally, Figure 3 A feasible example code is shown to implement the above process, and the main content includes: 1) Intercept system messages: This method is triggered when the system processes LAUNCH_ACTIVITY messages (a message type used by Android internally to start an Activity).

[0037] 2) Reflectively modify the Intent: Extract the placeholder Intent: Obtain the current Intent (which has been replaced with StubActivity, such as TextActivity) from the message object.

[0038] Extract the real Intent: Retrieve the original target Intent (the plugin Activity to be actually launched) from the Extra.

[0039] Replace the Component: Replace the component of the placeholder Intent with the component information of the plugin Activity.

[0040] 3) Complete the Activity launch: Call mBaseHandler.handleMessage(msg) to continue the original system launch process. At this time, the Intent already points to the actual plugin Activity.

[0041] Furthermore, the hot update process includes: When detecting an update to the sub - APK version, download the updated sub - APK file; Achieve dynamic update of application functions by replacing Dex files and resources, without the need to repackage the host APK or upload it to the app market.

[0042] Specifically, use DexClassLoader to load the un - installed plugin apk, then obtain the dexElements array of the plugin apk. The dexElements encapsulates Element, and Element internally encapsulates DexFile, which is used to load dex files. That is to say, the dexElements array stores all the classes of the plugin. Then obtain the dexElements array in the application, which stores all the classes in the application. Finally, merge these two dexElements arrays and assign the merged array to the dexElements variable of the application. At this time, the application has all the classes in the plugin.

[0043] Optionally, Figure 4 Shows a piece of feasible sample code for dynamically merging Dex files, merging the dexElements (compiled classes of the host) of the host APK with the dexElements1 (newly added or updated classes) of the plugin APK into a new array finalArray.

[0044] Android's class loader (PathClassLoader) loads Dex files through the dexElements array in DexPathList. After merging, the host APK can load both its own and the plugin's classes, achieving the pluginization function.

[0045] Code step breakdown: 1) Create a new array: Use the code Array.newInstance(...) to generate a new array with the same type as dexElements and a length equal to the sum of the two.

[0046] 2) Copy the host Dex elements: Use the code System.arraycopy(dexElements, 0, finalArray, 0, dexElements.length) to copy the Dex elements of the host APK to the starting position of the new array.

[0047] 3) Copy the plugin Dex elements: Use the code System.arraycopy(dexElements1, 0, finalArray, dexElements.length...) to append the Dex elements of the plugin APK after the host elements to form a complete merged array.

[0048] This embodiment also provides an Android application system for implementing the above Android application hot update method based on a plugin framework, which includes: A host APK module for providing core functions and a dynamic loading framework; A plugin management module responsible for downloading, parsing, and resource injection of sub-APKs; A Hook proxy module including a ProxyInstrumentation class and reflection replacement logic; A message interception module for overriding Handler.Callback and replacing the target component in the Intent.

[0049] This embodiment also provides a computer-readable storage medium storing a computer program, which when executed by a processor implements the steps of the above Android application hot update method based on a plugin framework.

[0050] In summary, the embodiments of the present invention provide an Android application hot update method, an Android application system, and a computer-readable medium based on a plug-in framework. Different from traditional plug-in solutions that only focus on module decoupling, the hot update process is embedded in the plug-in framework, and by dynamically replacing the code in the sub-APK, it is possible to fix bugs or update functions without having to resubmit to the app store. At the same time, by reflecting and replacing the system mInstrumentation field, the Activity startup process is dynamically intercepted, solving the key problem that plug-in Activities cannot pass system verification. This method is more direct and has higher compatibility compared to traditional class loader solutions. This method improves the update efficiency (bypassing app market review), optimizes the APK size, and enhances compatibility, having clear commercial and technical value.

[0051] The foregoing are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for hot updating an Android application based on a plug-in framework, characterized in that: The following steps are involved: S1. Splitting the Android application into a host APK and at least one sub-APK module, wherein the host APK contains core functions and the sub-APK module contains dynamically loadable plug-in functions or update codes; S2. Generate a proxy class ProxyInstrumentation by hooking the system Instrumentation class in the host APK, rewrite the execStartActivity method, and replace the target Activity with StubActivity to bypass Android system component verification; S3. When the application is started, the mInstrumentation field of the host APK is replaced by the ProxyInstrumentation instance through reflection; S4. Dynamically load the Dex files and resources in the child APK, intercept the Activity startup process through the message processing layer, and replace the target component in the Intent with the actual plug-in Activity.

2. According to the plug-in framework-based Android application hot update method of claim 1, it is characterized in that: The loading of the sub-APK module in step S1 is on-demand loading, including the following sub-steps: S1.1 When the user triggers a specific function, the corresponding sub-APK file is downloaded from the server; S1.2 Merge the Dex file in the child APK into the class loader of the host APK and parse its resource path.

3. The Android application hot update method based on the plug-in framework according to claim 1 is characterized in that: The specific implementation of the Hook system Instrumentation class includes: Create a ProxyInstrumentation class that inherits from Instrumentation and override the execStartActivity method; In the execStartActivity method, replace the target Activity in the original Intent with StubActivity, and store the original Activity information in the additional field of the Intent; Modify the mInstrumentation field of the host APK's Activity instance to a ProxyInstrumentation object through reflection.

4. The Android application hot update method based on the plug-in framework according to claim 1 is characterized in that: The implementation of the message processing layer includes: Rewrite the handleMessage method of the Handler.Callback interface to intercept LAUNCH_ACTIVITY type messages; Extract the original target Activity from the Intent additional field of the message and replace StubActivity with the actual plug-in Activity.

5. The method for hot updating Android applications based on a plug-in framework according to claim 1, characterized in that: The sub-APK module is packaged in an independent compilation manner, and the components declared in its AndroidManifest.xml do not need to be pre-registered in the host APK.

6. The Android application hot update method based on the plug-in framework according to any one of claims 1 to 5, characterized in that: The hot update process includes: When a sub-APK version update is detected, download the updated sub-APK file; Dynamically update application functions by replacing Dex files and resources without repackaging the host APK or putting it on the application market.

7. An Android application system that implements the Android application hot update method based on a plug-in framework as described in any one of claims 1 to 6, characterized in that: include: Host APK module, used to provide core functions and dynamic loading framework; The plug-in management module is responsible for downloading, parsing and injecting resources into the sub-APK; Hook proxy module, including ProxyInstrumentation class and reflection replacement logic; Message interception module, used to rewrite Handler.Callback and replace the target component in Intent.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the Android application hot update method based on the plug-in framework described in any one of claims 1 to 6 are implemented.