Application installation package generation method and device, electronic equipment and readable storage medium
By generating multiple target installation packages containing configuration information for specific functional requirements, the problem of excessive volume of Android application installation packages is solved, and the effect of reducing volume and improving compilation efficiency is achieved.
Patent Information
- Application Number
- CN202510298900.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-06-27
AI Technical Summary
During the development of Android applications, in order to adapt to the needs of different user groups, developers need to continuously add configuration information, which leads to a significant increase in the volume of the application installation package. How to reduce the volume of the installation package has become a technical challenge.
By responding to a compilation request, a first installation package of the target application is generated and copied into a plurality of second installation packages, each second installation package containing application configuration information for specific functional requirements, thereby generating a target installation package for different functional requirements.
It effectively reduces the size of the target installation package, avoids the need to recompile the entire application, and improves the compilation efficiency of installation packages for different functional requirements.
Smart Images

Figure CN120216008A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technologies, and more particularly, to a method, an apparatus, an electronic device, and a readable storage medium for generating an application installation package in the field of electronic device technologies. Background Art
[0002] In the development of Android applications, engineering compilation is a crucial step. However, as the types of user groups are growing more and more, in order to enable an application (APP) to meet the needs of different user groups, developers often continuously add new configuration information to the APP, so that the APP runs different functions to satisfy different user groups. However, after continuously adding new configuration information to the APP, the code for writing the APP will increase significantly, resulting in a relatively large volume of the installation package of the APP.
[0003] Therefore, how to reduce the volume of the installation package of the APP is a technical problem that urgently needs to be solved at present. Summary of the Invention
[0004] The present application provides a method, an apparatus, an electronic device, and a readable storage medium for generating an application installation package, and the method can reduce the volume of the application installation package.
[0005] In a first aspect, a method for generating an application installation package is provided. The method includes: in response to a compilation request for a target application program, generating a first installation package of the target application program, where the compilation request is used to request the generation of at least two installation packages, and one installation package corresponds to one functional requirement; copying the first installation package to obtain at least two second installation packages, where the number of the second installation packages is the same as the number of functional requirements corresponding to the compilation request, and the at least two second installation packages include the first installation package; obtaining application configuration information of at least two functional requirements corresponding to the compilation request, where the application configuration information is used to configure the target application program to meet the corresponding functional requirements; and writing the application configuration information of the at least two functional requirements into the at least two second installation packages respectively to obtain at least two target installation packages.
[0006] In the above technical solution, when a compilation request for a target application is received, and the compilation request is used to request the generation of at least two installation packages, with one installation package corresponding to one functional requirement, the first installation package of the target application can be first compiled and packaged, and then the first installation package can be copied as a base installation package to obtain at least two second installation packages. The number of the second installation packages is the same as the number of functional requirements corresponding to the compilation request. Then, the application configuration information of at least two functional requirements corresponding to the compilation request is obtained, and the application configuration information of each functional requirement is respectively written into the second installation package to obtain the target installation package corresponding to each functional requirement, that is, different target installation packages are used to meet different functional requirements. Since each obtained target installation package only contains the application configuration information corresponding to the corresponding functional requirement, in other words, each target installation package does not contain the application configuration information corresponding to all the functions of the target application, the volume of the target installation package can be effectively reduced. In addition, since the target installation package corresponding to each functional requirement is obtained by writing the application configuration information on the basis of the first installation package, there is no need to recompile the entire target application, thereby reducing the compilation time of the target installation packages containing different application configuration information and improving the compilation efficiency of the target installation packages corresponding to different functional requirements.
[0007] Combined with the first aspect and the above implementation manner, in some possible implementation manners, generating a first installation package of a target application in response to a compilation request for the target application includes: in response to the compilation request for the target application, obtaining the source code of the target application from a source code library; based on a preset compilation environment, compiling the source code into an executable file, where the executable file is a file that can be executed by a computer; obtaining the common resource files and common configuration information in the target application, where the common resource files refer to the static resources shared in the target application, and the common configuration information refers to the configuration parameters shared in the target application; and packaging the executable file, the common resource files, and the common configuration information based on a packaging tool to obtain the first installation package.
[0008] In the above technical solution, during the process of generating the first installation package of the target application, packaging the common resource files and the common configuration information can reduce the storage and transmission of duplicate resources. In addition, since the generated first installation package contains the necessary resource files and configuration information, the first installation package can be successfully installed and run in any environment.
[0009] Combined with the first aspect and the above implementation manners, in some possible implementation manners, before generating the first installation package of the target application, the method further includes: writing the application configuration information corresponding to each function of the target application into a target directory, and generating a file name, where the target directory is in response to the compilation of the target application; obtaining the application configuration information of at least two function requirements corresponding to the compilation request, including: calling a target function, and based on the target function and the file name, reading the application configuration information of at least two function requirements corresponding to the compilation request written in the target directory, where the target function is used to locate the position of the application configuration information of at least two function requirements in the target directory and read the application configuration information of at least two function requirements.
[0010] In the above technical solution, before generating the first installation package of the target application, the application configuration information corresponding to each function of the target application can be stored in the target directory, so that the application configuration information can be managed and modified independently of the source code of the target application. Thus, when configuring different functions for the target application, only the application configuration information needs to be updated, and there is no need to modify the source code of the target application, thereby simplifying the maintenance work of developers; in addition, by locating and reading the application configuration information through the target function and the file name, the reading efficiency can be improved and unnecessary search time can be reduced.
[0011] Combined with the first aspect and the above implementation manners, in some possible implementation manners, each function requirement corresponds to an identifier, and the identifier is associated with the application configuration information; before generating the first installation package of the target application, the method further includes: writing the application configuration information corresponding to each function of the target application into a database; obtaining the application configuration information of at least two function requirements corresponding to the compilation request, including: determining the identifier of each function requirement, and based on the identifier of each function requirement, obtaining the application configuration information associated with the identifier of each function requirement from the database to obtain the application configuration information of at least two function requirements.
[0012] In the above technical solution, by assigning a unique identifier to each function requirement and associating it with the application configuration information, the accuracy of the application configuration information of each function requirement can be ensured.
[0013] Combined with the first aspect and the above implementation manners, in some possible implementation manners, writing the application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages includes: detecting whether the formats of the application configuration information of at least two functional requirements are correct; when the formats of the application configuration information of at least two functional requirements are correct, compressing the application configuration information of each functional requirement based on a compression algorithm to obtain the compressed application configuration information of at least two functional requirements; and writing the compressed application configuration information of at least two functional requirements into the second installation packages respectively to obtain at least two target installation packages.
[0014] In the above technical solution, when obtaining at least two target installation packages, by detecting whether the formats of the application configuration information of at least two functional requirements are correct, incorrect formats in the application configuration information can be discovered and corrected in advance to ensure that the application configuration information of each functional requirement conforms to the expected format, thereby ensuring that the generated target installation packages can run successfully; in addition, when the formats of the application configuration information are correct, using a compression algorithm to compress the application configuration information can significantly reduce the volume of the application configuration information, thereby reducing the volume of the generated target installation packages.
[0015] Combined with the first aspect and the above implementation manners, in some possible implementation manners, each target installation package corresponds to an initial digital signature, and the digital signature is used to verify whether the target installation package has been illegally tampered with. The method further includes: after obtaining at least two target installation packages, deleting the initial digital signatures of at least two target installation packages; performing a hash calculation on each file in each target installation package based on a hash algorithm to generate a first hash value for each target installation package; and encrypting each first hash value based on a preset private key to regenerate a target digital signature for each target installation package.
[0016] It should be noted that, to ensure the security of the first installation package, a digital signature is generated for the first installation package based on each file in the first installation package to verify whether the configuration information in the first installation package has been tampered with. It can be understood that each second installation package copied from the first installation package will have the same digital signature, and each target installation package obtained from the second installation package will also have the same digital signature, that is, each target installation package corresponds to an initial digital signature. However, after writing the application configuration information of at least two functional requirements into at least two second installation packages to obtain at least two target installation packages, since the configuration information in the target installation package is inconsistent with the configuration information in the first installation package, the digital signature generated based on each file in the target installation package is inconsistent with the initial digital signature, resulting in the target installation package failing to pass the verification during installation. Therefore, to avoid the target installation package failing to pass the verification during installation, in the above technical solution, after obtaining at least two target installation packages, the initial digital signature of each target installation package can be deleted and each target installation package can be re-signed to ensure that the obtained target installation package can pass the verification smoothly during installation.
[0017] Combined with the first aspect and the above implementation manners, in some possible implementation manners, after regenerating a target digital signature for each target installation package, the method further includes: decrypting the target digital signature of each target installation package based on the public key corresponding to the private key to obtain a first hash value corresponding to each target installation package; re-performing hash calculation on each file in each target installation package based on the hash algorithm to regenerate a second hash value for each target installation package; comparing each first hash value with the corresponding second hash value. If the first hash value is the same as the corresponding second hash value, it is determined that the application configuration information in the target installation package has not been tampered with or lost during the re-signature process, otherwise, the target installation package needs to be regenerated and re-signed.
[0018] In the above technical solution, after regenerating a target digital signature for each target installation package, by comparing the regenerated second hash value with the first hash value obtained after decrypting the target digital signature, in the case where the second hash value is different from the first hash value, that is, in the case where the application configuration information in the target installation package has been tampered with or lost during the re-signature process, the target installation package is regenerated and re-signed, so as to ensure the accuracy of the application configuration information in the finally obtained target installation package, and further ensure that the generated target installation package can meet the corresponding functional requirements.
[0019] In a second aspect, an application installation package generation device is provided, and the device includes:
[0020] A generation module, configured to generate a first installation package of a target application in response to a compilation request for the target application, where the compilation request is used to request the generation of at least two installation packages, and one installation package corresponds to one functional requirement;
[0021] A copying module, configured to copy the first installation package to obtain at least two second installation packages, where the number of the second installation packages is the same as the number of functional requirements corresponding to the compilation request, and the at least two second installation packages include the first installation package;
[0022] An obtaining module, configured to obtain application configuration information of at least two functional requirements corresponding to the compilation request, where the application configuration information is used to configure the target application to meet the corresponding functional requirements;
[0023] A writing module, configured to write the application configuration information of at least two functional requirements into the at least two second installation packages respectively to obtain at least two target installation packages.
[0024] In a third aspect, an electronic device is provided. The electronic device includes a memory and a processor. The memory is used to store executable program code, and the processor is used to call and run the executable program code from the memory, so that the electronic device executes the application installation package generation method in the first aspect or any possible implementation manner of the first aspect.
[0025] In a fourth aspect, a computer program product is provided. The computer program product includes: computer program code, which when running on a computer, causes the computer to execute the application installation package generation method in the first aspect or any possible implementation manner of the first aspect.
[0026] In a fifth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores computer program code, which when running on a computer, causes the computer to execute the application installation package generation method in the first aspect or any possible implementation manner of the first aspect. Description of the Drawings
[0027] Figure 1 is a schematic diagram of the implementation environment of an application installation package generation method provided by an embodiment of the present application;
[0028] Figure 2 is a schematic flowchart of an application installation package generation method provided by an embodiment of the present application;
[0029] Figure 3 is a schematic flowchart of another application installation package generation method provided by an embodiment of the present application;
[0030] Figure 4It is a schematic structural diagram of an application installation package generation device provided by an embodiment of the present application;
[0031] Figure 5 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0032] Next, the technical solutions in the present application will be clearly and elaborately described in conjunction with the accompanying drawings. Among them, in the description of the embodiments of the present application, unless otherwise specified, " / " means "or". For example, A / B may mean A or B. The "and / or" in the text is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B may mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of the present application, "a plurality" means two or more than two.
[0033] Hereinafter, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as implying or suggesting relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features.
[0034] Before introducing the application installation package generation method provided by the embodiments of the present application, first introduce the implementation environment of the application installation package generation method provided by the embodiments of the present application. Refer to Figure 1 , Figure 1 It is a schematic diagram of the implementation environment of an application installation package generation method provided by an embodiment of the present application.
[0035] Exemplarily, as Figure 1 shown, the implementation environment includes: an electronic device 101 and a server 102.
[0036] Among them, the electronic device 101 can be any one of devices with the ability to generate installation packages such as a smart phone, a notebook computer, a desktop computer, or a virtual reality terminal. The embodiments of the present application do not make any limitations in this regard. The electronic device 101 can run various different types of application programs. For example, the application programs run by the electronic device 101 may include one or more of the following application programs: a drawing application program, a game application program, a video application program, a telephone application program, a social application program, a live broadcast application program, an email application program, a digital camera application program, a spreadsheet application program, etc.
[0037] The server 102 can be an independent physical server, a server cluster or a distributed file system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The embodiments of the present application do not limit this.
[0038] In a possible implementation manner, the server 102 is directly or indirectly connected to the terminal 101 through a wired or wireless communication method. The embodiments of the present application do not limit this.
[0039] In a possible implementation manner, when the electronic device 101 receives a compilation request for a target application program, and the compilation request is used to request the generation of at least two installation packages, with one installation package corresponding to one functional requirement, the electronic device 101 generates a first installation package of the target application program, copies the first installation package to obtain at least two second installation packages. The number of second installation packages is the same as the number of functional requirements corresponding to the compilation request. The at least two second installation packages include the first installation package. Then, the electronic device 101 obtains the application configuration information of at least two functional requirements corresponding to the compilation request. The application configuration information is used to configure the target application program to meet the corresponding functional requirements. Finally, the electronic device 101 writes the application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages.
[0040] In a possible implementation manner, the electronic device 101 can obtain the application configuration information of at least two functional requirements corresponding to the compilation request from the database of the server 102.
[0041] After introducing the implementation environment of the application installation package generation method provided by the embodiments of the present application, the application installation package generation method provided by the embodiments of the present application will be introduced below.
[0042] Next, through Figure 2 the method of the embodiments of the present application will be introduced in detail.
[0043] Figure 2 is a schematic flowchart of an application installation package generation method provided by the embodiments of the present application.
[0044] Exemplarily, as Figure 2 shown, taking the electronic device 101 in Figure 1 as the execution subject as an example, the method 200 includes the following steps 201-step 204.
[0045] Step 201, in response to a compilation request for a target application, generate a first installation package for the target application, where the compilation request is used to request the generation of at least two installation packages, and one installation package corresponds to one functional requirement.
[0046] Wherein, the target application is an application to be run. For example, the target application can be a navigation application to be run, a weather forecast application, a vehicle-to-mobile interconnection application, a driving recorder application, a drawing application, a game application, a video application, a phone application, a social application, a live broadcast application, an email application, a digital camera application, or a spreadsheet application, etc., and the embodiments of the present application do not limit this.
[0047] Wherein, each functional requirement is used to characterize at least one function that the target application needs to have. For example, the target application corresponds to two installation packages. Among them, the functional requirement corresponding to one installation package is used to characterize that the target application needs to support a Chinese interface and have functions of receiving payments and reconciling accounts; the functional requirement corresponding to the other installation package is used to characterize that the target application needs to support an English interface and have a payment function. That is, each functional requirement can also be regarded as a function set that the target application needs to have.
[0048] In a possible implementation manner, the compilation request for the target application can be triggered by a developer on an electronic device, or can be automatically triggered by the electronic device according to a preset triggering rule, and the embodiments of the present application do not limit this.
[0049] In a possible implementation manner, when a developer manually triggers a compilation request for a target application on an electronic device, and the compilation request is used to request the generation of at least two installation packages, and one installation package corresponds to one functional requirement, the electronic device can generate a first installation package for the target application in response to the compilation request for the target application.
[0050] Next, the implementation process of generating the first installation package for the target application will be introduced in detail in four steps.
[0051] Step (1), obtain the source code of the target application from the source code library.
[0052] Wherein, the source code library is a centralized or distributed system for storing and managing the source code of the target application.
[0053] In a possible implementation manner, the electronic device can clone the latest source code of the target application from the source code library to the local through a command-line tool (such as the Git command) to obtain the source code of the target application.
[0054] Step (2), based on a preset compilation environment, compile the source code into an executable file, where the executable file is a file that can be executed by a computer.
[0055] Among them, the compilation environment refers to a set of software tools and configurations used to support the compilation process of the source code.
[0056] This compilation environment generally includes a compiler, a linker, and environment variables.
[0057] Specifically, the compiler is used to convert the source code of the target application (such as C, C++, or Java, etc.) into object code. This object code is usually code in a binary format that can be recognized by a computer, and generates an object file for the converted object code. Then, the linker links the compiled object file and the library file together based on the library path specified by the environment variable to generate a file that can be executed by the computer, that is, an executable file. It can be understood that the executable file is a binary file generated after compilation and linking, which can enable the computer to directly load and execute.
[0058] Step (3), obtain the common resource files and common configuration information in the target application.
[0059] Among them, the common resource file refers to the static resources shared in the target application. For example, the common resource file can include image files for icons and background images used to display the user interface, style sheets used to define the appearance style of the target application, and audio files for sound effects and background music used to notify users, etc.
[0060] The common configuration information refers to the configuration parameters shared in the target application. For example, the common configuration information can include API endpoints (API Endpoints) used to define the URL address for the target application to communicate with the backend server, keys and tokens (Keys and Tokens) used to ensure the running security of the target application, such as API keys, OAuth tokens, etc., and color information used to define the color theme of the target application.
[0061] It can be understood that the common resource files and common configuration information are located in specific directories. For example, directories such as resources, assets, or config. In a possible implementation manner, the location of the common resource files and common configuration information, that is, the directory where they are located, can be found by means of a script. After finding the location of the common resource files and common configuration information, copy the common resource files and common configuration information to a temporary directory for subsequent packaging use.
[0062] Step (4): Based on a packaging tool, package the executable file, public resource files, and public configuration information to obtain a first installation package.
[0063] Among them, the packaging tool can be any tool capable of packaging the executable file, public resource files, and public configuration information. For example, packaging tools such as ZIP, Tar, MSI, NSIS, or JAR are not limited in this embodiment of the present application.
[0064] Specifically, after obtaining the public resource files and public configuration information in the target application, a packaging command corresponding to the packaging tool can be executed based on the packaging tool to package the executable file, public resource files, and public configuration information to obtain a first installation package.
[0065] Exemplarily, when the packaging tool is ZIP, after obtaining the public resource files and public configuration information in the target application, a packaging command corresponding to ZIP (i.e., the ZIP command) can be executed based on ZIP to package the executable file, public resource files, and public configuration information to obtain a first installation package.
[0066] It should be noted that in order to prevent the files in the first installation package from being illegally tampered with and ensure the security of the first installation package, after generating the first installation package, a hash calculation can also be performed on each file in the first installation package based on a hash algorithm to generate a hash value for the first installation package; and encrypt the hash value based on a preset private key to generate a digital signature for the first installation package, and this digital signature is used to verify whether the first installation package has been illegally tampered with.
[0067] Among them, the hash algorithm (also known as a hash function) is an algorithm that converts data of any length into an output of a fixed length.
[0068] Optionally, the hash algorithm can be any one of MD5, SHA-256, BLAKE2, or RIPEMD-160, etc., and this embodiment of the present application is not limited thereto.
[0069] Exemplarily, when the hash algorithm is SHA-256 and the first installation package includes File A and File B, the electronic device can use File A and File B as inputs and use the hashlib library in Python to calculate the content in File A and File B to obtain a hash value. For example, the hash value calculated by the electronic device using the hashlib library in Python is e9c4f7e0a6b.
[0070] Further, after obtaining the hash value, the electronic device may encrypt the hash value based on an asymmetric encryption algorithm, such as RSA or ECDSA, using a preset private key, and the encrypted output is the digital signature of the first installation package.
[0071] Among them, the private key is preset by the developer and used to generate the digital signature for the installation package. It should be noted that when the developer sets the private key, a public key corresponding to the private key will also be set, that is, the public key, which is used to verify the authenticity of the digital signature, and can also be understood as being used to verify whether the files in the first installation package have been tampered with when installing the first installation package.
[0072] Step 202, copy the first installation package to obtain at least two second installation packages. The number of second installation packages is the same as the number of functional requirements corresponding to the compilation request. The at least two second installation packages include the first installation package.
[0073] Among them, the second installation package can be understood as a copy of the installation package based on the first installation package, and the second installation package can be the same as the original first installation package.
[0074] In a possible implementation manner, after packing the executable file, the public resource file, and the public configuration information based on the packing tool to obtain the first installation package, command line tools such as xcopy or robocopy can be used to copy the first installation package to obtain at least two second installation packages.
[0075] In another possible implementation manner, after packing the executable file, the public resource file, and the public configuration information based on the packing tool to obtain the first installation package, the shutil.copytree() function of Python can also be used to copy the first installation package to obtain at least two second installation packages.
[0076] Step 203, obtain the application configuration information of at least two functional requirements corresponding to the compilation request. The application configuration information is used to configure the target application to meet the corresponding functional requirements.
[0077] Specifically, after copying the first installation package to obtain at least two second installation packages, the application configuration information of at least two functional requirements corresponding to the compilation request can be obtained, so that the application configuration information is written into the second installation packages respectively, thereby obtaining the target installation package corresponding to each functional requirement.
[0078] It should be noted that in order to simplify the maintenance work of developers, when configuring different functions for the target application, only the application configuration information needs to be updated, and the source code of the target application does not need to be modified. In a possible implementation manner, before generating the first installation package of the target application, the application configuration information corresponding to each function of the target application can be written into the target directory, and a file name can be generated, so that the application configuration information can be managed and modified independently of the source code of the target application. Therefore, when configuring different functions for the target application, only the application configuration information needs to be updated, and the source code of the target application does not need to be modified, thus simplifying the maintenance work of developers.
[0079] Among them, the target directory is a directory that will not modify the written application configuration information during the process of responding to the compilation request of the target application. For example, the target directory can be the assets directory.
[0080] Specifically, before generating the first installation package of the target application, a Python script or a Bash script can be used to write the application configuration information corresponding to each function of the target application into the target directory, and a unique file name can be generated based on the timestamp, the version number of the target application, or a specific identifier.
[0081] Exemplarily, the electronic device can run the following code to write the application configuration information corresponding to each function of the target application into the target directory:
[0082] config_file_path = '. / config'
[0083] config_file = open(config_file_path, 'w')
[0084] config_file.close()
[0085] configs = [config1, config2, config3]
[0086] for apk in apks:
[0087] apk_split = os.path.splitext(apk)
[0088] apk_file_name = apk_split[0]
[0089] apk_file_suffix = apk_split[1]
[0090] config_dir = apks_dir + " / configs_apks / "
[0091] if not os.path.exists(config_dir):
[0092] os.makedirs(config_dir)
[0093] For config in configs:
[0094] config_apk = config_dir + apk_file_name + "-" + config + apk_file_suffix
[0095] shutil.copy(os.path.join(apks_dir, apk), config_apk)
[0096] config_file = open(config_file_path, 'w')
[0097] config_file.write(config)
[0098] config_file.close()
[0099] config_zip_apk = zipfile.ZipFile(config_apk, "a", zipfile.ZIP_DEFLATED) config_zip_apk.write(config_file_path, "assets / config")
[0100] config_zip_apk.close()
[0101] Furthermore, after writing the application configuration information corresponding to each function of the target application into the target directory, the electronic device can call the target function and, based on the target function and the file name, read the application configuration information corresponding to at least two function requirements written into the target directory for the compilation request.
[0102] Among them, the target function is used to locate the position of the application configuration information of at least two function requirements in the target directory and read the application configuration information of at least two function requirements.
[0103] Exemplarily, the electronic device can run the following code to read the application configuration information corresponding to at least two function requirements written into the target directory for the compilation request:
[0104] @Throws(I0Exception::class)
[0105] fun readFileFromAssets(context: Context, fileName: String?): String {
[0106] val assetManager = context.assets
[0107] var inputStream: InputStream? = null
[0108] val stringBuilder = StringBuilder()
[0109] try {
[0110] inputStream = assetManager.open(fileName!!)
[0111] val reader = BufferedReader(InputStreamReader(inputStream))
[0112] var line: String?
[0113] while (reader.readLine().also { line = it}!= null) {
[0114] stringBuilder.append(line)
[0115] }
[0116] } finally {
[0117] inputStream?.close()
[0118] }
[0119] return stringBuilder.toString()
[0120] }
[0121] In another possible implementation, before generating the first installation package of the target application, application configuration information corresponding to each function of the target application can also be written into the database.
[0122] Specifically, before generating the first installation package of the target application, application configuration information corresponding to each function of the target application can also be written into the database using a Python script or an SQLAlchemy script.
[0123] In a possible implementation, to ensure the accuracy of the application configuration information for each functional requirement obtained, each functional requirement can correspond to an identifier, which is associated with the application configuration information. For example, a compilation request is used to request the generation of two installation packages, and the two installation packages respectively correspond to a functional requirement. Among them, the identifier corresponding to one functional requirement is F001, and this identifier 001 is associated with the application configuration information of the user payment function. The identifier corresponding to the other functional requirement is F002, and this identifier F001 is associated with the application configuration information of the user collection and reconciliation function.
[0124] Furthermore, after writing the application configuration information corresponding to each function of the target application into the database, the identifier of each functional requirement can be determined first, and then based on the identifier of each functional requirement, the application configuration information associated with the identifier of each functional requirement can be obtained from the above database, so as to obtain the application configuration information of at least two functional requirements.
[0125] Specifically, after writing the application configuration information corresponding to each function of the target application into the database, task management tools such as Jira and Trello can be used to obtain the identifier of each functional requirement, and an SQL query statement can be used to query the application configuration information associated with the identifier of each functional requirement from the above database, so as to obtain the application configuration information of at least two functional requirements.
[0126] Step 204, write the application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages.
[0127] Specifically, after obtaining the application configuration information of at least two functional requirements corresponding to the compilation request, a Python script or a Shell script can be used to write the application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages.
[0128] Next, the implementation method of obtaining at least two target installation packages will be introduced in detail in three steps.
[0129] Step (1), detect whether the formats of the application configuration information of at least two functional requirements are correct.
[0130] It should be noted that, in order to avoid writing application configuration information in an incorrect format into the second installation package, which may cause the final target installation package to fail to run successfully. That is, in a possible implementation, before writing the application configuration information of at least two functional requirements into at least two second installation packages respectively, it is possible to detect whether the format of the application configuration information of at least two functional requirements is correct, that is, whether the format of the application configuration information of each functional requirement conforms to a predefined format (for example, formats such as JSON, XML, or YAML), so as to avoid writing application configuration information that does not conform to the predefined format into the second installation package, thereby ensuring that the final obtained target installation package can run successfully.
[0131] Specifically, before writing the application configuration information of at least two functional requirements into at least two second installation packages respectively, validation tools such as jsonschema, yamllint, XML Schema, or RelaxNG can be used to detect the format of the application configuration information.
[0132] Step (2), when the formats of the application configuration information of at least two functional requirements are correct, compress the application configuration information of each functional requirement based on a compression algorithm to obtain the compressed application configuration information of at least two functional requirements.
[0133] Specifically, when the formats of the application configuration information of at least two functional requirements are correct, compression algorithms such as gzip, bzip2, or lzma can be used to compress the application configuration information of each functional requirement to obtain the compressed application configuration information of at least two functional requirements.
[0134] Step (3), write the compressed application configuration information of at least two functional requirements into the second installation package respectively to obtain at least two target installation packages.
[0135] Specifically, after obtaining the compressed application configuration information of at least two functional requirements, Python scripts or Shell scripts can be used to write the compressed application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages.
[0136] In summary, for the application installation package generation method provided in the embodiments of the present application, when a compilation request for a target application program is received, and the compilation request is used to request the generation of at least two installation packages, with one installation package corresponding to one functional requirement, the first installation package of the target application program can be first compiled and packaged, and then the first installation package is used as a base installation package for copying to obtain at least two second installation packages. The number of the second installation packages is the same as the number of functional requirements corresponding to the compilation request. Then, the application configuration information of at least two functional requirements corresponding to the compilation request is obtained, and the application configuration information of each functional requirement is respectively written into the second installation package to obtain the target installation package corresponding to each functional requirement, that is, different target installation packages are used to meet different functional requirements. Since each obtained target installation package only contains the application configuration information corresponding to the corresponding functional requirement, in other words, each target installation package does not contain the application configuration information corresponding to all the functions of the target application program, the volume of the target installation package can be effectively reduced; in addition, since the target installation package corresponding to each functional requirement is obtained by writing the application configuration information on the basis of the first installation package, there is no need to recompile the entire target application program, thereby reducing the compilation time of the target installation packages containing different application configuration information and improving the compilation efficiency of the target installation packages corresponding to different functional requirements; in addition, before the application configuration information of at least two functional requirements is respectively written into at least two second installation packages, by detecting whether the formats of the application configuration information of at least two functional requirements are correct, it is possible to avoid writing the application configuration information that does not conform to the predefined format into the second installation package, thereby ensuring that the finally generated target installation package can run successfully, and when the format of the application configuration information is correct, a compression algorithm can be used to compress the application configuration information to reduce the volume of the application configuration information, thereby further reducing the volume of the generated target installation package.
[0137] Figure 3 It is a schematic flowchart of another application installation package generation method provided in the embodiments of the present application.
[0138] Exemplarily, as Figure 3 shown, taking the electronic device 101 in Figure 1 as the execution subject as an example, the method 300 includes the following steps 301-step 310.
[0139] Step 301, in response to a compilation request for a target application program, generate a first installation package of the target application program, where the compilation request is used to request the generation of at least two installation packages, and one installation package corresponds to one functional requirement.
[0140] Step 302, copy the first installation package to obtain at least two second installation packages.
[0141] Step 303: Obtain the application configuration information of at least two functional requirements corresponding to the compilation request.
[0142] Step 304: Write the application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages.
[0143] For steps 301 - 304, reference can be made to the above embodiments, and details will not be elaborated here.
[0144] Step 305: Delete the initial digital signatures of at least two target installation packages.
[0145] As can be seen from the above embodiments, after generating the first installation package, a digital signature will be generated for the first installation package to ensure its security. Then it can be understood that each second installation package copied from the first installation package will have the same digital signature, and each target installation package obtained from the second installation package will also have the same digital signature, that is, each target installation package corresponds to an initial digital signature. However, after writing the application configuration information of at least two functional requirements into at least two second installation packages to obtain at least two target installation packages, since the configuration information in the target installation packages is inconsistent with the configuration information in the first installation package, the digital signatures generated based on the respective files in the target installation packages are inconsistent with the initial digital signatures, resulting in the target installation packages being unable to pass the verification during installation. Therefore, in order to avoid the target installation packages being unable to pass the verification during installation, in a possible implementation manner, after obtaining at least two target installation packages, a Shell script can be used to delete the initial digital signatures of each target installation package and re - sign each target installation package to ensure that the obtained target installation packages can be successfully installed and run.
[0146] Step 306: Perform hash calculation on each file in each target installation package based on the hash algorithm to generate a first hash value for each target installation package.
[0147] Step 307: Encrypt each first hash value based on a preset private key to regenerate a target digital signature for each target installation package.
[0148] For the implementation manners of steps 306 and 307, they are the same as the implementation manner of generating the digital signature for the first installation package in the above embodiments. For details, reference can be made to the above embodiments, and details will not be elaborated here.
[0149] Step 308: Decrypt the target digital signature of each target installation package based on the public key corresponding to the private key to obtain the first hash value corresponding to each target installation package.
[0150] It should be noted that after generating a target digital signature for each target installation package again, in order to ensure that the application configuration information in the target installation package has not been tampered with or lost during the re-signing process, in a possible implementation manner, the apksigner tool can be used to decrypt the target digital signature of each target installation package with the public key corresponding to the private key to obtain a first hash value corresponding to each target installation package, so as to facilitate subsequent comparison of the first hash value obtained by decryption with the second hash value re-generated for the target installation package, thereby determining whether the application configuration information in the target installation package has been tampered with or lost during the re-signing process based on the comparison result.
[0151] Step 309: Re-perform hash calculation on each file in each target installation package based on the hash algorithm to re-generate a second hash value for each target installation package.
[0152] Among them, the implementation manner of step 309 can refer to the above embodiments and will not be elaborated here.
[0153] Step 310: Compare each first hash value with the corresponding second hash value. If the first hash value is the same as the corresponding second hash value, it is determined that the application configuration information in the target installation package has not been tampered with or lost during the re-signing process; otherwise, the target installation package needs to be re-generated and re-signed.
[0154] Exemplarily, when the first hash value is e7c2f3e0a6d and the second hash value corresponding to this first hash value is e7c2f3e0a6d, since the first hash value is the same as the corresponding second hash value, it can be determined in this case that the application configuration information in the target installation package has not been tampered with or lost during the re-signing process; when the first hash value is e7c2f3e0a6d and the second hash value corresponding to this first hash value is c6c2a3e0a4e, since the first hash value is different from the corresponding second hash value, it can be determined in this case that the application configuration information in the target installation package has been illegally tampered with or lost during the re-signing process. Therefore, in order to ensure that the target installation package can pass the verification smoothly during installation, at this time, the target installation package needs to be re-generated and re-signed.
[0155] It should be noted that after generating a target digital signature for each target installation package again, by comparing the regenerated second hash value with the first hash value obtained after decryption, in the case where the second hash value is different from the first hash value, that is, in the case where the application configuration information in the target installation package is tampered with or lost during the re-signature process, the target installation package is regenerated and re-signed, so as to ensure the accuracy of the application configuration information in the finally obtained target installation package, and further ensure that the generated target installation package can meet the corresponding functional requirements.
[0156] Figure 4 It is a schematic structural diagram of an application installation package generation device provided by an embodiment of the present application.
[0157] Exemplarily, as Figure 4 shown, the device 400 includes:
[0158] A generation module 401, configured to generate a first installation package of a target application program in response to a compilation request for the target application program, where the compilation request is used to request the generation of at least two installation packages, and one installation package corresponds to one functional requirement;
[0159] A copying module 402, configured to copy the first installation package to obtain at least two second installation packages, where the number of second installation packages is the same as the number of functional requirements corresponding to the compilation request, and the at least two second installation packages include the first installation package;
[0160] An acquisition module 403, configured to acquire application configuration information of at least two functional requirements corresponding to the compilation request, where the application configuration information is used to configure the target application program to meet the corresponding functional requirements;
[0161] A writing module 404, configured to write the application configuration information of at least two functional requirements into at least two second installation packages respectively to obtain at least two target installation packages.
[0162] In a possible implementation manner, the acquisition module 403 is further configured to acquire the source code of the target application program from a source code library in response to a compilation request for the target application program; the generation module 401 is specifically configured to compile the source code into an executable file based on a preset compilation environment, where the executable file is a file that can be executed by a computer; the acquisition module 403 is further configured to acquire a common resource file and common configuration information in the target application program, where the common resource file refers to static resources shared in the target application program, and the common configuration information refers to configuration parameters shared in the target application program; the generation module 401 is specifically further configured to package the executable file, the common resource file, and the common configuration information based on a packaging tool to obtain the first installation package.
[0163] In a possible implementation, the writing module 404 is further configured to write application configuration information corresponding to each function of the target application into a target directory and generate a file name before generating a first installation package of the target application. The target directory is a directory that will not modify the written application configuration information during the process of responding to the compilation request for the target application. The apparatus further includes a calling module configured to call a target function, and an obtaining module 403 specifically configured to read, based on the target function and the file name, the application configuration information of at least two function requirements corresponding to the compilation request written into the target directory. The target function is configured to locate the position of the application configuration information of at least two function requirements in the target directory and read the application configuration information of at least two function requirements.
[0164] In a possible implementation, each function requirement corresponds to an identifier, and the identifier is associated with the application configuration information. The writing module 404 is further configured to write the application configuration information corresponding to each function of the target application into a database before generating a first installation package of the target application. The obtaining module 403 is specifically configured to determine the identifier of each function requirement and obtain, based on the identifier of each function requirement, the application configuration information associated with the identifier of each function requirement from the database to obtain the application configuration information of at least two function requirements.
[0165] In a possible implementation, the apparatus further includes a detection module configured to detect whether the formats of the application configuration information of at least two function requirements are correct. The apparatus further includes a compression module configured to, when the formats of the application configuration information of at least two function requirements are correct, compress the application configuration information of each function requirement based on a compression algorithm to obtain the compressed application configuration information of at least two function requirements. The writing module 404 is specifically configured to write the compressed application configuration information of at least two function requirements into a second installation package respectively to obtain at least two target installation packages.
[0166] In a possible implementation, each target installation package corresponds to an initial digital signature, and the digital signature is used to verify whether the target installation package has been illegally tampered with. The apparatus further includes a deletion module configured to delete the initial digital signatures of at least two target installation packages after obtaining at least two target installation packages. The generation module 401 is further configured to perform a hash calculation on each file in each target installation package based on a hash algorithm to generate a first hash value for each target installation package, and encrypt each first hash value based on a preset private key to regenerate a target digital signature for each target installation package.
[0167] In a possible implementation, the device further includes a decryption module, configured to decrypt the target digital signature of each target installation package based on the public key corresponding to the private key after generating a target digital signature for each target installation package again, to obtain a first hash value corresponding to each target installation package; the generation module 401 is further configured to re-perform hash calculation on each file in each target installation package based on a hash algorithm to generate a second hash value for each target installation package again; the device further includes a judgment module, configured to compare each first hash value with the corresponding second hash value, and if the first hash value is the same as the corresponding second hash value, determine that the application configuration information in the target installation package has not been tampered with or lost during the re-signature process, otherwise, it is necessary to generate the target installation package again and perform the signature again.
[0168] Figure 5 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
[0169] Exemplarily, as Figure 5 shown, the electronic device 500 includes: a memory 501 and a processor 502. Among them, an executable program code 503 is stored in the memory 501, and the processor 502 is configured to call and execute the executable program code 503 to execute an application installation package generation method.
[0170] In addition, an embodiment of the present application also protects a device, which may include a memory and a processor. Among them, an executable program code is stored in the memory, and the processor is configured to call and execute the executable program code to execute an application installation package generation method provided by an embodiment of the present application.
[0171] In this embodiment, the device can be divided into functional modules according to the above method example. For example, it can correspond to each functional module, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is illustrative, only a logical function division, and there may be other division methods in actual implementation.
[0172] In the case of dividing each functional module corresponding to each function, the device may further include a first sending module, a second sending module, a torque zeroing module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be cited in the function description of the corresponding functional module, and will not be repeated here.
[0173] It should be understood that the device provided in this embodiment is used to execute the above application installation package generation method, so it can achieve the same effect as the above implementation method.
[0174] In the case of adopting an integrated unit, the device may include a processing module and a storage module. Among them, when the device is applied to an electronic device, the processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device to execute relevant program codes and the like.
[0175] Among them, the processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules, and circuits shown in combination with the disclosure of this application. The processor may also be a combination that realizes computing functions, such as including a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.
[0176] In addition, the device provided in the embodiments of this application may specifically be a chip, a component, or a module. The chip may include a processor and a memory connected thereto; among them, the memory is used to store instructions. When the processor calls and executes the instructions, the chip may execute an application installation package generation method provided in the above embodiments.
[0177] This embodiment also provides a computer-readable storage medium. Computer program code is stored in the computer-readable storage medium. When the computer program code runs on a computer, it causes the computer to execute the above-related method steps to implement an application installation package generation method provided in the above embodiments.
[0178] This embodiment also provides a computer program product. When the computer program product runs on a computer, it causes the computer to execute the above-related steps to implement an application installation package generation method provided in the above embodiments.
[0179] Among them, the device, computer-readable storage medium, computer program product, or chip provided in this embodiment is all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be elaborated here.
[0180] Through the description of the above embodiments, those skilled in the art can understand that for the convenience and simplicity of description, only the above division of each functional module is used as an example. In actual applications, the above functions may be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
[0181] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of devices or units can be in electrical, mechanical or other forms.
[0182] The above content is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed in the present application can easily think of changes or substitutions, which should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A method for generating an application installation package, characterized in that: The method comprises: In response to a compilation request for a target application, generating a first installation package of the target application, wherein the compilation request is used to request generation of at least two installation packages, one installation package corresponding to one functional requirement; Copying the first installation package to obtain at least two second installation packages, the number of the second installation packages being the same as the number of functional requirements corresponding to the compilation request, and the at least two second installation packages including the first installation package; Acquire application configuration information of at least two functional requirements corresponding to the compilation request, wherein the application configuration information is used to configure the target application to meet the corresponding functional requirements; The application configuration information of the at least two functional requirements is written into the at least two second installation packages respectively to obtain at least two target installation packages.
2. The method according to claim 1, characterized in that The step of generating a first installation package of the target application in response to a compilation request for the target application includes: In response to a compilation request for a target application, obtaining source code of the target application from a source code library; Based on a preset compilation environment, compile the source code into an executable file, where the executable file is a file that can be executed by a computer; Acquire common resource files and common configuration information in the target application, wherein the common resource files refer to static resources shared in the target application, and the common configuration information refers to configuration parameters shared in the target application; The executable file, the public resource file, and the public configuration information are packaged based on a packaging tool to obtain the first installation package.
3. The method according to claim 1, characterized in that Before generating the first installation package of the target application, the method further includes: Writing application configuration information corresponding to each function of the target application into a target directory and generating a file name, wherein the target directory is a directory in which the written application configuration information will not be modified in the process of responding to a compilation request for the target application; The obtaining application configuration information of at least two functional requirements corresponding to the compilation request includes: Call a target function, and based on the target function and the file name, read application configuration information of at least two functional requirements corresponding to the compilation request written in the target directory, wherein the target function is used to locate the application configuration information of the at least two functional requirements in the target directory and read the application configuration information of the at least two functional requirements.
4. The method according to claim 1, characterized in that: Each of the functional requirements corresponds to an identifier, and the identifier is associated with the application configuration information; Before generating the first installation package of the target application, the method further includes: writing application configuration information corresponding to each function of the target application into a database; The obtaining application configuration information of at least two functional requirements corresponding to the compilation request includes: An identifier of each of the functional requirements is determined, and based on the identifier of each of the functional requirements, application configuration information associated with the identifier of each of the functional requirements is acquired from the database to obtain application configuration information of the at least two functional requirements.
5. The method according to claim 1, characterized in that The step of writing the application configuration information of the at least two functional requirements into the at least two second installation packages respectively to obtain at least two target installation packages comprises: Detecting whether the formats of the application configuration information of the at least two functional requirements are correct; When the formats of the application configuration information of the at least two functional requirements are correct, compressing the application configuration information of each functional requirement based on a compression algorithm to obtain compressed application configuration information of the at least two functional requirements; The compressed application configuration information of at least two functional requirements is written into the second installation package respectively to obtain the at least two target installation packages.
6. The method according to claim 1, characterized in that Each of the target installation packages corresponds to an initial digital signature, and the digital signature is used to verify whether the target installation package has been illegally tampered with. The method further includes: After obtaining the at least two target installation packages, deleting the initial digital signatures of the at least two target installation packages; Performing hash calculation on each file in each of the target installation packages based on a hash algorithm to generate a first hash value for each of the target installation packages; Each of the first hash values is encrypted based on a preset private key to regenerate a target digital signature for each of the target installation packages.
7. The method according to claim 6, characterized in that After regenerating a target digital signature for each target installation package, the method further includes: Decrypting the target digital signature of each target installation package based on a public key corresponding to the private key to obtain a first hash value corresponding to each target installation package; Re-calculating the hash value of each file in each target installation package based on the hash algorithm to regenerate a second hash value for each target installation package; Compare each of the first hash values with each of the corresponding second hash values. If the first hash value is the same as the corresponding second hash value, it is determined that the application configuration information in the target installation package has not been tampered with or lost during the re-signing process. Otherwise, the target installation package needs to be regenerated and re-signed.
8. An application installation package generation device, characterized in that: The device comprises: A generating module, configured to generate a first installation package of the target application in response to a compilation request for the target application, wherein the compilation request is used to request generation of at least two installation packages, one installation package corresponding to one functional requirement; a copy module, configured to copy the first installation package to obtain at least two second installation packages, the number of the second installation packages being the same as the number of functional requirements corresponding to the compilation request, the at least two second installation packages including the first installation package; An acquisition module, used to acquire application configuration information of at least two functional requirements corresponding to the compilation request, wherein the application configuration information is used to configure the target application to meet the corresponding functional requirements; The writing module is used to write the application configuration information of the at least two functional requirements into the at least two second installation packages respectively to obtain at least two target installation packages.
9. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 7 is implemented.