Android application packaging method, device, equipment and storage medium
By using Gradle configuration files and depth-first algorithm to handle parameter conflicts in the packaging process of Android applications, the compilation failure problem caused by parameter conflicts in the existing technology is solved, and an efficient packaging process is achieved.
Patent Information
- Application Number
- CN202210268247.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-18
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2042-03-18
AI Technical Summary
The packaging methods of existing Android applications are prone to failure in compiling due to parameter conflicts during resource compilation.
By receiving and responding to the packaging instructions entered by the user, obtaining the Android project to be packaged, and adding the Gradle sub-configuration file in the root directory of each business sub-project, adding the Gradle main configuration file in the root directory of the Android project, and introducing the sub-configuration file into the main configuration file. Based on preset template rules and depth-first algorithms, each Gradle configuration file is compiled to generate multiple packaging tasks, handle the path depth of conflicting parameters, and generate effective packaging tasks.
It solves the problem of compilation failure caused by parameter conflicts, improves packaging efficiency, and ensures the correct generation of Android application packages.
Smart Images

Figure CN114610318B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of base frame operation and maintenance, and in particular to a packaging method, device, equipment and storage medium for an Android application. Background Art
[0002] Gradle is a project automation build tool based on the concepts of Apache Ant and Apache Maven. It uses a domain specific language (DSL) based on Groovy to declare project settings, abandoning various cumbersome configurations based on Extensible Markup Language (XML). Its adaptability and richness allow general design principles to be directly applied in the build. The industry usually packages Android applications based on Gradle to generate application packages that run in the Android environment.
[0003] The existing packaging method of Android applications is prone to compilation failure due to conflicts in some parameters during the resource compilation process. Summary of the invention
[0004] The main purpose of the present invention is to solve the problem that the existing Android application packaging method causes compilation failure due to parameter conflicts.
[0005] A first aspect of the present invention provides a packaging method for an Android application, comprising:
[0006] Receiving and responding to a packaging instruction input by a user, obtaining an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each of the business sub-projects includes a business application;
[0007] Adding Gradle sub-configuration files to the root directory of each business sub-project, respectively, wherein each Gradle primary configuration file defines an external variable tag, and the external variable tag is used to indicate the dependencies and version information required for the business application to run;
[0008] Add a Gradle main configuration file in the root directory of the Android project, and introduce each of the Gradle sub-configuration files into the Gradle main configuration file respectively, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run;
[0009] Compile each Gradle configuration file to generate multiple packaging tasks based on preset template rules and depth-first algorithm;
[0010] Execute each of the packaging tasks respectively to obtain the Android application package corresponding to the Android project.
[0011] Optionally, in a first implementation of the first aspect of the present invention, compiling each Gradle configuration file based on a preset template rule and a depth-first algorithm to generate a plurality of packaging tasks includes:
[0012] Traverse each Gradle configuration file. If the traversal detects conflicts in target parameters between Gradle configuration files, calculate the path depth of each configuration file where the conflicting target parameters are located.
[0013] Overwrite the remaining conflicting target parameters with the target parameters in the configuration file with the maximum path depth until the traversal is completed, and obtain the traversed Gradle configuration files;
[0014] Based on the preset template rules, the traversed Gradle configuration files are compiled respectively to obtain multiple packaging tasks, wherein each of the Gradle configuration files is compiled into a corresponding packaging task.
[0015] Optionally, in a second implementation of the first aspect of the present invention, before compiling each Gradle configuration file based on a preset template rule and a depth-first algorithm to generate a plurality of packaging tasks, the method further includes:
[0016] A version update instruction sent by a receiving terminal is updated, and external variable tags in each of the Gradle sub-configuration files and the Gradle main configuration file are updated according to the version update instruction.
[0017] Optionally, in a third implementation of the first aspect of the present invention, before respectively executing each of the packaging tasks to obtain the Android application package corresponding to the Android project, the method further includes:
[0018] Obtaining the task files corresponding to the packaging tasks, and determining whether the task files are abnormal;
[0019] Obtain the task file with the exception and receive the modification command parameters entered by the user;
[0020] The task file with the abnormality is corrected using the modification command parameter based on the IO stream.
[0021] Optionally, in a fourth implementation of the first aspect of the present invention, the respectively executing each of the packaging tasks to obtain an Android application package corresponding to the Android project includes:
[0022] The packaging tasks are batch-executed in a multi-threaded manner to obtain an Android application package corresponding to the Android project.
[0023] Optionally, in a fifth implementation of the first aspect of the present invention, the method further includes:
[0024] Obtain a preset encryption and decryption dependency package, wherein the encryption and decryption dependency package includes a Gradle encryption script for encrypting resource files and code files, a decryption entry function, and an interception function for intercepting a Java layer system API;
[0025] According to the Gradle encryption script, the data in the Android application package is encrypted, and a decryption entry function and an interception function for intercepting the Java layer system API are inserted.
[0026] Optionally, in a sixth implementation of the first aspect of the present invention, the method further includes:
[0027] Simulating an Android operating environment, and pre-starting the Android project in the simulated Android operating environment based on the Android application package, to obtain a target loading order of multiple class files included in the Android project during the pre-start process;
[0028] Adjusting the arrangement order of the plurality of class files according to the target loading order;
[0029] Based on the multiple class files after the order is adjusted, the Android application package is reconstructed, and based on the reconstructed Android application package, the Android project is started in the simulated Android operating environment.
[0030] A second aspect of the present invention provides a packaging device for an Android application, comprising:
[0031] A data acquisition module, used to receive and respond to a packaging instruction input by a user, and acquire an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each of the business sub-projects includes a business application;
[0032] A sub-project configuration module, used to add Gradle sub-configuration files to the root directory of each business sub-project, wherein each Gradle primary configuration file defines an external variable tag, and the external variable tag is used to indicate the dependencies and version information required for the business application to run;
[0033] A main project configuration module, used to add a Gradle main configuration file in the root directory of the Android project, and introduce each of the Gradle sub-configuration files into the Gradle main configuration file, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run;
[0034] The compilation module is used to compile various Gradle configuration files to generate multiple packaging tasks based on preset template rules and depth-first algorithm;
[0035] The packaging module is used to execute each of the packaging tasks respectively to obtain the Android application package corresponding to the Android project.
[0036] Optionally, in a first implementation manner of the second aspect of the present invention, the compiling module specifically includes:
[0037] The file traversal unit is used to traverse each Gradle configuration file. If the traversal detects that there is a conflict in the target parameters between the Gradle configuration files, the path depth of the configuration file where each conflicting target parameter is located is calculated respectively;
[0038] The parameter overwriting unit is used to overwrite the remaining conflicting target parameters with the target parameters in the configuration file with the maximum path depth until the traversal is completed to obtain the Gradle configuration files after the traversal;
[0039] The task generation unit is used to compile the traversed Gradle configuration files based on preset template rules to obtain multiple packaging tasks, wherein each of the Gradle configuration files is compiled into a packaging task.
[0040] Optionally, in a second implementation of the second aspect of the present invention, the packaging module is specifically used to:
[0041] The packaging tasks are batch-executed in a multi-threaded manner to obtain an Android application package corresponding to the Android project.
[0042] Optionally, in a third implementation manner of the second aspect of the present invention, the device further includes a task modification module, and the task modification module specifically includes:
[0043] A file judging unit, used to obtain the task files corresponding to each of the packaging tasks, and judge whether each of the task files is abnormal;
[0044] A parameter receiving unit, used to obtain the task file with the anomaly and receive the modification command parameters input by the user;
[0045] The parameter modification unit is used to modify the task file with the abnormality by using the modification command parameter based on the IO stream.
[0046] Optionally, in a fourth implementation of the second aspect of the present invention, the device further includes a program package encryption module, and the program package encryption module specifically includes:
[0047] A dependency package acquisition unit, used to acquire a preset encryption and decryption dependency package, wherein the encryption and decryption dependency package includes a Gradle encryption script for encrypting resource files and code files, a decryption entry function, and an interception function for intercepting a Java layer system API;
[0048] The data encryption unit is used to encrypt the data in the Android application package according to the Gradle encryption script, and insert a decryption entry function and an interception function for intercepting the Java layer system API.
[0049] Optionally, in a fifth implementation of the second aspect of the present invention, the device further includes a project startup module, and the project startup module specifically includes:
[0050] A pre-start unit, used to simulate an Android operating environment, and pre-start the Android project in the simulated Android operating environment based on the Android application package, to obtain a target loading order of multiple class files included in the Android project during the pre-start process;
[0051] A reordering unit, used for adjusting the arrangement order of the plurality of class files according to the target loading order;
[0052] The reconstruction unit is used to reconstruct the Android application package based on the multiple class files after the order is adjusted, and start the Android project in the simulated Android operating environment based on the reconstructed Android application package.
[0053] A third aspect of the present invention provides an Android application packaging device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the Android application packaging device executes the above-mentioned Android application packaging method.
[0054] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned method for packaging an Android application.
[0055] In the technical solution provided by the present invention, by receiving and responding to the packaging instruction, the Android project to be packaged is obtained, the Gradle sub-configuration files are added to the root directory of each business sub-project in the Android project, the Gradle main configuration file is added to the root directory of the Android project, and each Gradle sub-configuration file is introduced into the Gradle main configuration file respectively, and each Gradle configuration file is compiled based on the preset template rules and the depth-first algorithm to generate multiple packaging tasks, that is, if there are multiple conflicting parameters, the path depth of the file where each parameter is located is calculated respectively, and finally the parameters in the file with the maximum path depth are used as valid parameters to generate the corresponding packaging tasks; each packaging task is executed respectively to obtain the Android application package corresponding to the Android project. The present invention adopts the depth-first algorithm to prioritize the conflicting parameters during the file compilation process, solves the problem of compilation failure caused by potential parameter conflicts, and thus improves the packaging efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 This is a schematic diagram of a first embodiment of a packaging method for an Android application in an embodiment of the present invention;
[0057] Figure 2 A schematic diagram of a second embodiment of a packaging method for an Android application in an embodiment of the present invention;
[0058] Figure 3 A schematic diagram of a third embodiment of a packaging method for an Android application in an embodiment of the present invention;
[0059] Figure 4 A schematic diagram of an embodiment of a packaging device for an Android application in an embodiment of the present invention;
[0060] Figure 5 It is a schematic diagram of another embodiment of a packaging device for an Android application in an embodiment of the present invention;
[0061] Figure 6 Schematic diagram of an embodiment of a packaging device for an Android application in an embodiment of the present invention. DETAILED DESCRIPTION
[0062] The embodiments of the present invention provide a packaging method, device, equipment and storage medium for an Android application, which have higher packaging efficiency.
[0063] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0064] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the packaging method of an Android application in an embodiment of the present invention includes:
[0065] 101. Receive and respond to a packaging instruction input by a user, and obtain an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each business sub-project includes a business application;
[0066] It is understandable that when an Android project is developed in an integrated development tool (such as Android Studio), the source code needs to be compiled and packaged into an Android application package (APK) before it can be installed in the Android operating system. Its essence is a compressed package, and the Android project is a folder containing source code files.
[0067] For an Android project, the whole project will be layered according to the product functions, that is, different layers will be divided into specific modules according to the actual business or functions. Among them, each business sub-project corresponds to a different module, for example, the product is divided into news module, video module, operation advertising module, login and registration module, etc. based on the business perspective. The main application is the shell project of the main application in the Android project, which is responsible for the resource and module scheduling of the Android application during operation, so as to output a complete application.
[0068] Optionally, for an Android project with complex functions, these modules are grouped, for example, there are two groups, "Moudle_App" and "Extends". The "Moudle_App" group includes "shell projects of each module" that have no impact on the main application construction, such as the shell project of the main application, the shell project of the news module, the shell project of the video module, etc.; and the "Extends" group includes basic functional modules for specific variants or build configurations, such as the Eguan module, the Dev module, etc. This not only makes the project more structured and facilitates the development work of developers, but also improves the efficiency of data indexing, thereby improving the efficiency of packaging and compilation.
[0069] At the same time, in addition to the above modules, a complete Android project should also include the AndroidManifest.xml file (global configuration file), assets folder (static resource folder), lib folder (third-party library resources), META-INF folder (security and integrity verification file), res folder (resource folder) and resource.arsc file (resource index file) required for packaging.
[0070] 102. Add Gradle sub-configuration files to the root directory of each business sub-project. External variable tags are defined in each Gradle primary configuration file. The external variable tags are used to indicate the dependencies and version information required for the business application to run.
[0071] It should be understood that, in theory, the Android application can be manually packaged and compiled by manually typing command line parameters in the terminal, but this packaging and compilation method is not only cumbersome, but also extremely inefficient.
[0072] Correspondingly, various tools developed by humans are productivity tools used to replace manual labor. Gradle is a tool for automated project construction. It declares project settings by using a domain-specific language based on Groovy, namely the Gradle configuration file.
[0073] After receiving the operation instructions indicated by the user, the terminal adds a Gradle sub-configuration file to the root directory of each business sub-project, so as to perform differentiated configuration of the compilation parameters of each business sub-project. The sub-configuration file is defined in advance by the user according to the requirements of packaging and compilation, such as the location of SDK and NDK, the dependencies and versions required for the operation of the business sub-project, and the required Java source code and resource files.
[0074] 103. Add a Gradle main configuration file in the root directory of the Android project, and introduce each Gradle sub-configuration file into the Gradle main configuration file respectively, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run;
[0075] It can be understood that the Gradle main configuration file is introduced into the project entry file in the Android project, and each Gradle sub-configuration file is introduced into the Gradle main configuration file, thereby forming a dependency chain of configuration parameters.
[0076] 104. Based on the preset template rules and depth-first algorithm, compile each Gradle configuration file to generate multiple packaging tasks;
[0077] It can be understood that the terminal first traverses each Gradle configuration file. If the traversal detects that there is a conflict in target parameters between the Gradle configuration files, the path depth of the configuration files where the conflicting target parameters are located is calculated respectively; the remaining conflicting target parameters are overwritten with the target parameters in the configuration file with the maximum path depth or the remaining conflicting target parameters are directly deleted until the traversal is completed to obtain the traversed Gradle configuration files; based on the preset template rules, the traversed Gradle configuration files are compiled respectively to obtain multiple packaging tasks, wherein each Gradle configuration file is compiled into a packaging task.
[0078] For the same common module parameter declared in each Gradle configuration file, that is, there is a parameter conflict between the two, for example, the name of the Android project is Android, and the common module parameter a is declared in the setting.gradle configuration file under the path "Android / " and the setting.gradle configuration file under the path "Android / Moudle_App / A / ", then their effective priority is determined according to the "depth first algorithm", and the depth first refers to the "path depth" of the configuration file relative to the root directory of the Android project. For example, the unit path depth is "1", the file path depth corresponding to the setting.gradle configuration file under the path "Android / " is 1, and the path depth corresponding to the setting.gradle configuration file under the path "Android / Moudle_App / A / " is 3. Then, during compilation, the latter is determined to be valid and its content is compiled into the corresponding packaging task. This embodiment does not limit the method for determining the validity of the parameters in the configuration file. The conflicting parameters in the file less than the maximum path depth can be directly removed, or the parameters in the maximum path depth file can be used to overwrite other conflicting parameters.
[0079] The preset template rules are the compilation syntax rules defined at the bottom layer of the Gradle tool. The terminal parses the Gradle main configuration file and its dependent Gradle sub-configuration files according to the compilation syntax rules, generates corresponding packaging tasks according to the contents declared in the configuration files, and obtains multiple packaging tasks.
[0080] Optionally, before the terminal compiles each Gradle file, it may also receive a version update instruction sent by the terminal, and update the external variable tags in each Gradle configuration file according to the version update instruction.
[0081] Since the Gradle configuration files defined separately realize the distributed management of external variables, when at least one plug-in function module is updated, the external variable labels of the corresponding plug-in function modules in the Gradle configuration files can be directly updated according to the version update instructions sent by the terminal, which is convenient for version management and maintenance.
[0082] 105. Execute each packaging task respectively to obtain the Android application package corresponding to the Android project.
[0083] It is understandable that the terminal executes various packaging tasks to compile and package the Android project according to the specified packaging parameters to obtain the corresponding Android application package. Specifically, first call the Android resource packaging tool aapt to parse the AndroidManifest.xml file in the Android project, collect the resource files and xml files in the res folder of the Android project, compress and compile them, and obtain the packaged resource files. In this process, the resource id is assigned and the R.java file and the arsc file are generated. Secondly, call the compiler Javac to compile the generated R.java file to generate the corresponding class file; then, use Javac to continue to convert the generated class file into a dex file supported by the Davik virtual machine, and use the apkbuilder tool to merge the dex file and the compiled resources into a single unsigned apk file; finally, sign the unsigned apk file and align it to obtain the final Android application package.
[0084] Preferably, the terminal can run various packaging tasks simultaneously based on multi-threading to improve packaging efficiency.
[0085] Optionally, before executing each packaging task, the terminal can also obtain the task files corresponding to each packaging task and determine whether each task file is abnormal; if there is an abnormal task file, the task file with the abnormality is obtained, and the modification command parameters entered by the user are received, and then the task file with the abnormality is corrected based on the IO stream using the modification command parameters to ensure normal compilation of the packaging task.
[0086] In this embodiment, by using a depth-first algorithm to prioritize conflicting parameters during file compilation, the problem of compilation failure caused by potential parameter conflicts is solved, thereby improving packaging efficiency.
[0087] See also Figure 2 , a second embodiment of the packaging method of an Android application in an embodiment of the present invention includes:
[0088] 201. Receive and respond to a packaging instruction input by a user, and obtain an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each business sub-project includes a business application;
[0089] 202. Add a Gradle sub-configuration file to the root directory of each business sub-project. In each Gradle primary configuration file, an external variable tag is defined. The external variable tag is used to indicate the dependencies and version information required for the business application to run.
[0090] 203. Add a Gradle main configuration file in the root directory of the Android project, and introduce each Gradle sub-configuration file into the Gradle main configuration file respectively, wherein the Gradle main configuration file defines external variable tags for indicating dependencies and version information required for the main application to run;
[0091] 204. Based on the preset template rules and depth-first algorithm, compile each Gradle configuration file to generate multiple packaging tasks;
[0092] 205. Execute each packaging task respectively to obtain the Android application package corresponding to the Android project.
[0093] Among them, steps 201-205 are similar to the execution steps of the above steps 101-105, and will not be repeated here.
[0094] 206. Simulate an Android operating environment, and pre-start an Android project in the simulated Android operating environment based on the Android application package, to obtain a target loading order of multiple class files included in the Android project during the pre-start process;
[0095] It is understandable that the terminal can simulate the Android operating environment through an Android virtual machine or other means to perform installation testing on the packaged Android application package. This embodiment does not limit the way in which the terminal simulates the Android operating environment.
[0096] During the pre-startup process of the application, the terminal will sequentially load the required multiple class files from the initial Android application package according to the startup requirements to complete the startup of the application in the simulated Android operating environment. Therefore, this step pre-starts the application through the initial Android application package, and can determine the loading order of multiple class files during the pre-startup process of the application.
[0097] The pre-startup process of this embodiment is essentially the same as the normal start-up process of the application program. Therefore, the loading order of multiple class files in the pre-startup process is the loading order of multiple class files in the formal start-up process.
[0098] 207. Adjust the order of multiple class files according to the target loading order;
[0099] It is understandable that after obtaining the loading order of multiple class files during the application startup process, the terminal adjusts the arrangement order of the multiple class files according to the loading order so that the arrangement order of the multiple class files is the same as the loading order of the multiple class files during the application startup process.
[0100] In a specific application scenario, the arrangement order of multiple class files can be adjusted according to the loading order by manual adjustment. In another specific application scenario, the arrangement order of multiple class files can also be adjusted according to the loading order by a binary processing tool in a preset format. The specific adjustment method is not limited here. Among them, the preset format can be set according to the actual situation and is not limited here.
[0101] 208. Reconstruct the Android application package based on the multiple class files after the order is adjusted, and start the Android project in the simulated Android operating environment based on the reconstructed Android application package.
[0102] It is understandable that the terminal reconstructs the Android application package based on the multiple class files after the arrangement order is adjusted, wherein the arrangement order of the multiple class files in the reconstructed Android application package is the same as the loading order. After the Android application package is reconstructed, the subsequent application startup can be implemented based on the reconstructed Android package.
[0103] Furthermore, after receiving the application startup instruction, the terminal starts the application based on the Android application package with the class file arrangement order adjusted. Among them, since the arrangement order of the class files in the reconstructed Android application package is the same as the loading order of the class files required to be loaded when the application is started, when loading the class files in the Android application, multiple class files can be directly obtained in sequence according to the loading order, avoiding the situation that during the startup process, the terminal needs to traverse all the class files in the entire reconstructed Android application package to obtain the required class files for loading as needed, thereby improving the startup speed of the Android project.
[0104] In this embodiment, the process of quickly starting the Android application package generated by packaging and compiling is described in detail. By adjusting the arrangement order of class files, the loading speed of class files is increased, thereby improving the startup speed of the Android project.
[0105] See also Figure 3 The fourth embodiment of the packaging method of the Android application in the embodiment of the present invention includes:
[0106] 301. Receive and respond to a packaging instruction input by a user, and obtain an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each business sub-project includes a business application;
[0107] 302. Add a Gradle sub-configuration file to the root directory of each business sub-project. In each Gradle primary configuration file, an external variable tag is defined. The external variable tag is used to indicate the dependencies and version information required for the business application to run.
[0108] 303. Add a Gradle main configuration file in the root directory of the Android project, and introduce each Gradle sub-configuration file into the Gradle main configuration file respectively, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run;
[0109] 304. Based on the preset template rules and depth-first algorithm, compile each Gradle configuration file to generate multiple packaging tasks;
[0110] 305. Execute each packaging task respectively to obtain an Android application package corresponding to the Android project.
[0111] Among them, steps 301-305 are similar to the execution steps of the above steps 101-105, and will not be repeated here.
[0112] 306. Obtain a preset encryption and decryption dependency package, wherein the encryption and decryption dependency package includes a Gradle encryption script for encrypting resource files and code files, a decryption entry function, and an interception function for intercepting a Java layer system API;
[0113] It is understandable that in order to improve the security of the Android application package, the terminal also encrypts it. Among them, the Gradle encryption script will trigger the encryption of the resource files and code files of the Android application during execution and replace the original plaintext files.
[0114] 307. According to the Gradle encryption script, encrypt the data in the Android application package, and insert a decryption entry function and an interception function for intercepting the Java layer system API.
[0115] It should be understood that the encryption process includes: encrypting and replacing assets directory resources, encrypting and replacing res directory resources, encrypting and replacing lib directory resources, and encrypting and replacing code files.
[0116] Specifically, the terminal executes the gradle script, thereby triggering the mergeDebugAssets function or the mergeReleaseAssets function to extract all resources in the assets directory, encrypt them and replace the original plaintext files; triggering the processDebugResources function or the processReleaseResources function to extract all resources in the res directory, encrypt them and replace the original plaintext files; triggering the stripDebugDebugSymbols function or the stripReleaseDebugSymbols function to extract all resources in the lib directory, encrypt them and replace the original plaintext files; triggering mergeDexDebug or mergeDexRelease to extract all classes.dex code files, encrypt them and replace the original plaintext files. Finally, the decryption entry function and the function used to intercept the Java layer system API are inserted into the Android application package.
[0117] In this embodiment, the process of encrypting the Android application package is described in detail, and the security is further effectively improved by encrypting the code files and resource files.
[0118] The above describes the packaging method of the Android application in the embodiment of the present invention. The following describes the packaging device of the Android application in the embodiment of the present invention. Figure 4 , an embodiment of the packaging device of the Android application in the embodiment of the present invention includes:
[0119] The data acquisition module 401 is used to receive and respond to the packaging instruction input by the user, and obtain the Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each of the business sub-projects includes a business application;
[0120] The sub-project configuration module 402 is used to add Gradle sub-configuration files to the root directory of each business sub-project, wherein each Gradle primary configuration file defines an external variable tag, and the external variable tag is used to indicate the dependency and version information required for the business application to run;
[0121] A main project configuration module 403 is used to add a Gradle main configuration file in the root directory of the Android project, and introduce each of the Gradle sub-configurations into the Gradle main configuration file, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run;
[0122] A compilation module 404 is used to compile various Gradle configuration files to generate multiple packaging tasks based on preset template rules and a depth-first algorithm;
[0123] The packaging module 405 is used to execute each of the packaging tasks respectively to obtain the Android application package corresponding to the Android project.
[0124] In this embodiment, by using a depth-first algorithm to prioritize conflicting parameters during file compilation, the problem of compilation failure caused by potential parameter conflicts is solved, thereby improving packaging efficiency.
[0125] See also Figure 5 Another embodiment of the packaging device of the Android application in the embodiment of the present invention includes:
[0126] The data acquisition module 501 is used to receive and respond to the packaging instruction input by the user, and obtain the Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each of the business sub-projects includes a business application;
[0127] A sub-project configuration module 502 is used to add a Gradle sub-configuration file to the root directory of each business sub-project, wherein each Gradle primary configuration file defines an external variable tag, and the external variable tag is used to indicate the dependency and version information required for the business application to run;
[0128] A main project configuration module 503, used to add a Gradle main configuration file in the root directory of the Android project, and introduce each of the Gradle sub-configurations into the Gradle main configuration file, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run;
[0129] A compilation module 504 is used to compile various Gradle configuration files to generate multiple packaging tasks based on preset template rules and a depth-first algorithm;
[0130] The packaging module 505 is used to execute each packaging task respectively to obtain an Android application package corresponding to the Android project;
[0131] The encryption module 506 is used to obtain a preset encryption and decryption dependency package, wherein the encryption and decryption dependency package includes a Gradle encryption script for encrypting resource files and code files, a decryption entry function, and an interception function for intercepting the Java layer system API; according to the Gradle encryption script, the data in the Android application package is encrypted, and the decryption entry function and the interception function for intercepting the Java layer system API are inserted.
[0132] The project startup module 507 is used to simulate the Android operating environment, and pre-start the Android project in the simulated Android operating environment based on the Android application package, and obtain the target loading order of multiple class files contained in the Android project during the pre-start process; adjust the arrangement order of the multiple class files according to the target loading order; reconstruct the Android application package based on the multiple class files after the order is adjusted, and start the Android project in the simulated Android operating environment based on the reconstructed Android application package.
[0133] The compiling module 504 specifically includes:
[0134] The file traversal unit 5041 is used to traverse each Gradle configuration file. If the traversal detects that there is a conflict of target parameters between the Gradle configuration files, the path depth of the configuration files where the conflicting target parameters are located is calculated respectively;
[0135] A parameter covering unit 5042 is used to cover the remaining conflicting target parameters with the target parameters in the configuration file with the maximum path depth until the traversal is completed to obtain the traversed Gradle configuration files;
[0136] The task generation unit 5043 is used to compile the traversed Gradle configuration files based on preset template rules to obtain multiple packaging tasks, wherein each of the Gradle configuration files is compiled into a corresponding packaging task.
[0137] The packaging module 505 is specifically used for:
[0138] The packaging tasks are batch-executed in a multi-threaded manner to obtain an Android application package corresponding to the Android project.
[0139] In the embodiment of the present invention, the modular design allows the hardware of each part of the packaging device of the Android application to focus on the realization of a certain function, thereby maximizing the performance of the hardware. At the same time, the modular design also reduces the coupling between the modules of the device, making maintenance more convenient.
[0140] above Figure 4 and Figure 5 The packaging device of the Android application in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The packaging device of the Android application in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0141] Figure 6 : is a schematic diagram of the structure of a packaging device for an Android application provided by an embodiment of the present invention. The packaging device 600 for the Android application may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 610 (for example, one or more processors) and a memory 620, and one or more storage media 630 (for example, one or more mass storage devices) storing applications 633 or data 632. Among them, the memory 620 and the storage medium 630 can be short-term storage or persistent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the packaging device 600 for the Android application. Furthermore, the processor 610 can be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the packaging device 600 for the Android application.
[0142] The Android application packaging device 600 may also include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input and output interfaces 660, and / or one or more operating systems 631, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 6The illustrated packaging device structure of the Android application does not constitute a limitation on the packaging device of the Android application, and may include more or less components than those illustrated, or may combine certain components, or may have different component arrangements.
[0143] The present invention also provides a packaging device for Android applications, the packaging device for Android applications comprising a memory and a processor, the memory storing computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the steps of the risk monitoring method for financial products in the above-mentioned embodiments.
[0144] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the risk monitoring method for financial products.
[0145] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0146] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0147] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A packaging method for an Android application, characterized in that: The packaging method of the Android application comprises: Receiving and responding to a packaging instruction input by a user, obtaining an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each of the business sub-projects includes a business application; Adding a Gradle sub-configuration file to the root directory of each business sub-project, wherein each Gradle sub-configuration file defines an external variable tag, and the external variable tag is used to indicate the dependencies and version information required for the business application to run; Add a Gradle main configuration file in the root directory of the Android project, and introduce each of the Gradle sub-configuration files into the Gradle main configuration file respectively, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run; Compile each Gradle configuration file to generate multiple packaging tasks based on preset template rules and depth-first algorithm; Execute each of the packaging tasks respectively to obtain the Android application package corresponding to the Android project; The method of compiling each Gradle configuration file to generate multiple packaging tasks based on a preset template rule and a depth-first algorithm includes: traversing each Gradle configuration file, and if the traversal detects that there is a conflict in target parameters between the Gradle configuration files, respectively calculating the path depth of the configuration files where the conflicting target parameters are located; overwriting the remaining conflicting target parameters with the target parameters in the configuration file with the maximum path depth until the traversal is completed to obtain the traversed Gradle configuration files; and compiling each traversed Gradle configuration file based on a preset template rule to obtain multiple packaging tasks, wherein each of the Gradle configuration files is compiled into one packaging task.
2. The method for packaging an Android application according to claim 1, characterized in that: Before compiling each Gradle configuration file to generate multiple packaging tasks based on the preset template rules and the depth-first algorithm, the method further includes: A version update instruction sent by a receiving terminal is updated, and external variable tags in each of the Gradle sub-configuration files and the Gradle main configuration file are updated according to the version update instruction.
3. The packaging method of Android application according to claim 1, characterized in that: Before respectively executing each of the packaging tasks to obtain the Android application package corresponding to the Android project, the method further includes: Obtaining the task files corresponding to the packaging tasks, and determining whether the task files are abnormal; Obtain the task file with the exception and receive the modification command parameters entered by the user; The task file with the abnormality is corrected using the modification command parameter based on the IO stream.
4. The method for packaging an Android application according to claim 1, characterized in that: The respective execution of the packaging tasks to obtain the Android application package corresponding to the Android project includes: The packaging tasks are batch-executed in a multi-threaded manner to obtain an Android application package corresponding to the Android project.
5. The method for packaging an Android application according to claim 1, characterized in that: The method further comprises: Obtain a preset encryption and decryption dependency package, wherein the encryption and decryption dependency package includes a Gradle encryption script for encrypting resource files and code files, a decryption entry function, and an interception function for intercepting a Java layer system API; According to the Gradle encryption script, the data in the Android application package is encrypted, and a decryption entry function and an interception function for intercepting the Java layer system API are inserted.
6. The method for packaging an Android application according to any one of claims 1 to 5, characterized in that: The method further comprises: Simulating an Android operating environment, and pre-starting the Android project in the simulated Android operating environment based on the Android application package, to obtain a target loading order of multiple class files included in the Android project during the pre-start process; Adjusting the arrangement order of the plurality of class files according to the target loading order; Based on the multiple class files after the order is adjusted, the Android application package is reconstructed, and based on the reconstructed Android application package, the Android project is started in the simulated Android operating environment.
7. A packaging device for an Android application, characterized in that: The packaging device of the Android application comprises: A data acquisition module, used to receive and respond to a packaging instruction input by a user, and acquire an Android project to be packaged, wherein the root directory of the Android project includes a main application and at least one business sub-project, and each of the business sub-projects includes a business application; A sub-project configuration module, used to add Gradle sub-configuration files to the root directory of each business sub-project, wherein each Gradle sub-configuration file defines an external variable tag, and the external variable tag is used to indicate the dependencies and version information required for the business application to run; A main project configuration module, used to add a Gradle main configuration file in the root directory of the Android project, and introduce each of the Gradle sub-configuration files into the Gradle main configuration file, wherein the Gradle main configuration file defines external variable tags for indicating the dependencies and version information required for the main application to run; The compilation module is used to compile various Gradle configuration files to generate multiple packaging tasks based on preset template rules and depth-first algorithm; A packaging module, used to execute each packaging task respectively to obtain an Android application package corresponding to the Android project; The compilation module specifically includes: a file traversal unit, which is used to traverse each Gradle configuration file. If the traversal detects that there is a conflict in the target parameters between the Gradle configuration files, the path depth of the configuration files where the conflicting target parameters are located is calculated respectively; a parameter covering unit, which is used to cover the remaining conflicting target parameters with the target parameters in the configuration file with the maximum path depth until the traversal is completed to obtain the traversed Gradle configuration files; a task generation unit, which is used to compile the traversed Gradle configuration files respectively based on preset template rules to obtain multiple packaging tasks, wherein each of the Gradle configuration files is compiled into a corresponding packaging task.
8. A packaging device for an Android application, characterized in that: The packaging device of the Android application comprises: a memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instruction in the memory so that the Android application packaging device executes the Android application packaging method as described in any one of claims 1-6.
9. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the packaging method of the Android application as described in any one of claims 1-6 is implemented.
Citation Information
Patent Citations
Application program packaging method and device and terminal equipment
CN107315593A
Android application packaging and uploading method and device, computer device and storage medium
CN108418717A