CN113656044B - Android installation package compression method and device, computer equipment and storage medium - Google Patents

Android installation package compression method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN113656044B
CN113656044B CN202110975917.3A CN202110975917A CN113656044B CN 113656044 B CN113656044 B CN 113656044B CN 202110975917 A CN202110975917 A CN 202110975917A CN 113656044 B CN113656044 B CN 113656044B
Authority
CN
China
Prior art keywords
file
folder
task
installation package
name
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110975917.3A
Other languages
Chinese (zh)
Other versions
CN113656044A (en
Inventor
周浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202110975917.3A priority Critical patent/CN113656044B/en
Publication of CN113656044A publication Critical patent/CN113656044A/en
Application granted granted Critical
Publication of CN113656044B publication Critical patent/CN113656044B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Abstract

The invention discloses a method, a device, computer equipment and a storage medium for compressing an android installation package, wherein the method comprises the following steps: monitoring each task node of the android installation package packaging flow to obtain a task type corresponding to each task node, performing matching detection on the obtained task type and a designated type, if the designated type of task is detected, taking the designated type of task as a target task, acquiring a resource file corresponding to the target task, taking the target task as a first file, traversing file names in an input folder for executing the target task to obtain a binary extraction file with names corresponding to the first file, taking the binary extraction file as a second file, performing secondary compression on the second file to obtain a compressed resource file, replacing the second file with the compressed resource file, and performing compression packaging on the installation package file containing the updated input folder to obtain the compressed android installation package file. The invention can reduce the volume of the installation package and improve the compression efficiency and the data transmission efficiency.

Description

Android installation package compression method and device, computer equipment and storage medium
Technical Field
The invention relates to the technical field of mobile development, in particular to a method and a device for compressing android installation packages, computer equipment and a storage medium.
Background
With the development of mobile communication technology, application of android application programs is more and more widespread, developers install application programs by providing android installation packages (Android application package, APK) for users, the users use the application programs after the android installation packages are installed successfully, but with the improvement of user requirements, the installation packages are larger and larger, the download transmission time of the installation packages is longer, and meanwhile, more network transmission flow resources are required to be consumed, so that user experience is affected, and therefore, the android installation packages are required to be subjected to volume compression, so that efficiency in the data transmission process of the installation packages is improved.
At present, aiming at the volume compression of the android installation package, an automatic packing tool aapt in an android development package is mainly adopted to determine files to be compressed which need to be added into an APK file, and then the files to be compressed are compressed, so that the volume of the android installation package is reduced, the confusion compression of resources is mainly completed, but the compression effect is not obvious, and therefore, a compression method capable of effectively reducing the volume of the android installation package is needed.
Disclosure of Invention
The embodiment of the application provides a method, a device, computer equipment and a storage medium for compressing an android installation package, so that the volume of the android installation package is reduced, network transmission flow resources are saved, and the cost is reduced.
In order to solve the technical problems, an embodiment of the present application provides a method for compressing an android installation package, including:
monitoring each task node of the android installation package packaging flow, obtaining a task type corresponding to each task node, and carrying out matching detection on the obtained task type and a designated type to obtain a detection result;
if the detection result is that a task of a specified type is detected, the task of the specified type is taken as a target task, and a resource file corresponding to the target task is obtained and taken as a first file;
traversing and matching each file name in an input folder for executing the target task based on a naming mode corresponding to a preset file and a binary extraction file to obtain a binary extraction file with a name corresponding to the first file as a second file, wherein the input folder is a folder in an installation package file;
performing secondary compression on the second file to obtain a compressed resource file, and replacing the second file with the compressed resource file to obtain an updated input folder;
And compressing and packaging the installation package file containing the updated input folder to obtain a compressed android installation package file.
Optionally, the android installation package is monitored by adopting a project automation construction tool gradle.
Optionally, the obtaining a resource file corresponding to the target task, as a first file, includes:
in the execution stage of the construction, adding a resource file reading task by adding a doFirst method;
after the resource file reading task is executed, generating a debug log containing the resource file name;
and acquiring a resource file name from the debug log, and reading a file corresponding to the resource file name from all the input files as a first file.
Optionally, said replacing said second file with said compressed resource file comprises:
writing the compressed resource file into a temporary folder in the same path as the second file;
and deleting the second file, and updating the file name of the compressed resource file to the file name of the second file.
Optionally, traversing all input files for executing the target task based on a naming manner corresponding to the preset file and the binary extraction file to obtain the binary extraction file corresponding to the first file, where the binary extraction file serving as the second file includes:
Acquiring a naming mode corresponding to a preset file and a binary extraction file;
reading a first input file for executing the target task;
judging whether the read input file is a binary extraction file or not; if the read input file is a binary extraction file, determining the file name of an original file corresponding to the read input file based on the naming mode, and taking the file name as the original file name;
comparing the original file name with the file name of the first file to obtain a comparison result;
if the comparison results are different in name, reading the next input file, and returning to the step of judging whether the read input file is a binary extraction file for continuous execution;
and if the comparison result is that the names are the same, taking the read input file as a binary extraction file corresponding to the first file.
Optionally, comparing the original file name with the file name of the first file to obtain a comparison result includes: reading the character length of the original file name as a first length, and reading the file name of the first file as a second length;
if the first length is different from the second length, determining that the comparison results are different in name;
If the first length is the same as the second length, comparing the characters at each position in the sequence from front to back;
if the characters at any position are different, the comparison is terminated, the comparison result is determined to be different in name, and if the characters at each position are the same, the comparison result is determined to be the same in name.
Optionally, before compressing and packaging folders containing all the input files to obtain a compressed android installation package file, the android installation package compression method further includes:
in the construction process, unreferenced resource files in the res folder and the drawable folder are cleaned, and picture resources in the res folder and the drawable folder are subjected to lossless compression, so that updated res folder and updated drawable folder are obtained.
In order to solve the above technical problem, an embodiment of the present application further provides an android installation package compression device, including:
the task node monitoring module is used for monitoring each task node of the android installation package packaging flow, obtaining a task type corresponding to each task node, and carrying out matching detection on the obtained task type and a designated type to obtain a detection result;
The first file acquisition module is used for taking the task of the appointed type as a target task and acquiring a resource file corresponding to the target task as a first file if the detection result is that the task of the appointed type is detected;
the second file acquisition module is used for performing traversal matching on each file name in an input folder for executing the target task based on a naming mode corresponding to a preset file and a binary extraction file to obtain a binary extraction file with a name corresponding to the first file as a second file, wherein the input folder is a folder in an installation package file;
the second file updating module is used for carrying out secondary compression on the second file to obtain a compressed resource file, and replacing the second file with the compressed resource file to obtain an updated input folder;
and the installation package generation module is used for compressing and packaging the installation package file containing the updated input folder to obtain a compressed android installation package file.
Optionally, the first file obtaining module includes:
the task construction unit is used for adding a resource file reading task by adding a doFirst method in the construction execution stage;
The system comprises a log generating unit, a resource file reading unit and a resource file reading unit, wherein the log generating unit is used for generating a debugging log containing the name of a resource file after a resource file reading task is executed;
the file extraction unit is used for obtaining the resource file names from the debug log, and reading the files corresponding to the resource file names from all the input files to serve as first files.
Optionally, the second file updating module includes:
a file writing unit, configured to write the compressed resource file into a temporary folder that has the same path as the second file;
and the file replacing unit is used for deleting the second file and updating the file name of the compressed resource file into the file name of the second file.
The naming mode acquisition unit is used for acquiring naming modes corresponding to preset files and binary extraction files;
an input file reading unit for reading a first input file for executing the target task;
the file type judging unit is used for judging whether the read input file is a binary extraction file or not;
the original name acquisition unit is used for determining the file name of the original file corresponding to the read input file based on the naming mode if the read input file is a binary extraction file, and taking the file name as the original file name;
The name comparison unit is used for comparing the original file name with the file name of the first file to obtain a comparison result;
the loop iteration unit is used for reading the next input file if the comparison results are different in name, and returning to the step of judging whether the read input file is a binary extraction file for continuous execution;
and the result determining unit is used for taking the read input file as a binary extraction file corresponding to the first file if the comparison result is the same in name.
Optionally, the name comparison unit includes:
a length reading subunit, configured to read a character length of the original file name as a first length, and read a file name of the first file as a second length;
a first result determining subunit, configured to determine that the comparison result is different in name if the first length is different from the second length;
a second result determining subunit, configured to compare the characters at each position in the order from front to back if the first length is the same as the second length;
and the third result determining subunit is used for terminating the comparison if the characters at any position are different, determining that the comparison results are different in name, and confirming that the comparison results are the same in name if the characters at each position are the same.
Optionally, the android installation package compression device further includes:
the file cleaning and compressing module is used for cleaning unreferenced resource files in the res folder and the drawable folder in the construction process, and carrying out lossless compression on picture resources in the res folder and the drawable folder to obtain an updated res folder and an updated drawable folder.
In order to solve the technical problem, the embodiment of the application also provides a computer device, which comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the processor realizes the steps of the android installation package compression method when executing the computer program.
In order to solve the above technical problem, an embodiment of the present application further provides a computer readable storage medium, where a computer program is stored, where the computer program when executed by a processor implements the steps of the android installation package compression method described above.
According to the android installation package compression method, device, computer equipment and storage medium, through monitoring each task node of an android installation package packing flow, a task type corresponding to each task node is obtained, the obtained task type is matched with a designated type to obtain a detection result, if the detection result is that the designated type of task is detected, the designated type of task is used as a target task, a resource file corresponding to the target task is obtained and is used as a first file, traversing and matching are conducted on each file name in an input folder for executing the target task based on a naming mode corresponding to a preset file and a binary extraction file, the binary extraction file with the name corresponding to the first file is obtained, the binary extraction file is used as a second file, the second file is compressed to obtain a compressed resource file, the compressed resource file is adopted to replace the second file, the updated input folder is obtained, the installation package file containing the input folder is compressed and packed, the binary extraction file which does not affect installation of an application program is extracted and secondarily compressed, the installation package volume is reduced, the compression efficiency and the data transmission efficiency are improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments of the present application will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow chart of one embodiment of the android installation package compression method of the present application;
FIG. 3 is a schematic diagram of one embodiment of an android installation package compression apparatus in accordance with the present application;
FIG. 4 is a schematic structural diagram of one embodiment of a computer device in accordance with the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the applications herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having" and any variations thereof in the description of the application and the claims and the description of the drawings above are intended to cover a non-exclusive inclusion. The terms first, second and the like in the description and in the claims or in the above-described figures, are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Referring to fig. 1, as shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like.
The terminal devices 101, 102, 103 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server that provides various services, such as a background server that provides support for pages displayed on the terminal devices 101, 102, 103, and may be a stand-alone server, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
It should be noted that, the android installation package compression method provided by the embodiment of the application is executed by the server, and accordingly, the android installation package compression device is arranged in the server.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. Any number of terminal devices, networks and servers may be provided according to implementation requirements, and the terminal devices 101, 102, 103 in the embodiment of the present application may specifically correspond to application systems in actual production.
Referring to fig. 2, fig. 2 illustrates an android installation package compression method according to an embodiment of the present application, and an example of application of the method to the server in fig. 1 is described, where the embodiment of the present application may acquire and process related data based on an artificial intelligence technology. Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
Artificial intelligence infrastructure technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and other directions.
The specific details of this embodiment are as follows:
s201: and monitoring each task node of the android installation package packaging flow, obtaining a task type corresponding to each task node, and carrying out matching detection on the obtained task type and the designated type to obtain a detection result.
Specifically, in the process of packaging the android installation package, a plurality of task nodes exist, each task node is monitored to obtain a task type corresponding to each task node, the obtained task type is matched with a specified type to obtain a detection result, and a task of the specified type is obtained based on the detection result.
The task node refers to each task flow in the packaging process, and specifically includes, but is not limited to: detecting configuration files (e.g., android management. Xml), initializing attributes (e.g., minSdkVersion, and uses-sdk), adding referenced resource packages, collecting resource files, processing overlapping packages, adding files to a resource table, compiling values resources, assigning ids to bag resources, compiling resource files, and the like.
Among the task nodes, some of the task nodes relate to the processing of the compressible resource file, and the task corresponding to the task node related to the processing of the compressible resource file is used as a task of a designated type so as to acquire the compressible resource file through subsequent processing.
Wherein the specified type of task is used for subsequent retrieval of the compressible resource file.
Optionally, the project automation construction tool gradle is adopted to monitor the android installation package.
Wherein gradle is a building tool whose construction is based on a JVM-based dynamic language Groovy (DSL) for declaring construction and creation tasks, making dependency management simpler. The lifecycle of Gradle for building and executing includes three stages, namely an Initialization stage, a Configuration stage Configuration and an Execution stage. In this embodiment, a task of a specified type is preset, and each task node of the installation package is monitored through a gradle, so that a key task is rapidly screened out.
In the embodiment, the android installation package is monitored by adopting the construction tool gradle with higher automation degree, so that the method is convenient, the code development cost is reduced, and the monitoring efficiency is improved.
S202: if the detection result is that the task of the specified type is detected, the task of the specified type is taken as a target task, and a resource file corresponding to the target task is obtained and taken as a first file.
Specifically, the task of the designated type refers to a task of the same type as the preset type, in this embodiment, the designated type is determined based on an environment and a preset element, for example, the preset element is a certain package, "a task with a current channel environment name added at the beginning, the test environment is a package, the production environment is a package release, a task of the designated type is formed, and when the task of the designated type is detected, a resource file corresponding to the task of the designated type is obtained as the first file.
The process of obtaining the first file may refer to the description of the following embodiments, and in order to avoid repetition, details are not repeated here.
Optionally, the first file is a resources.
When the APK installation file is packaged, 2 important files related to the resource are generated, namely an r.java file and a resources.arsc file, wherein the r.java file is a class, identification information of some resources is stored in the r.java file, the resources.arsc file is a file for recording mapping information of the resources, for example, a file containing a table, representing header information, thread pool information and pool information of a character string, and for example, a picture resource named image_src needs to be loaded, and in a low resolution model, the android device analyzes the resources.arsc file and searches configuration information corresponding to low resolution mapping information drawable-xdpi corresponding to the picture resource based on an analysis result.
S203: and traversing and matching file names in an input folder for executing the target task based on a naming mode corresponding to the preset file and the binary extraction file to obtain a binary extraction file with the name corresponding to the first file as a second file, wherein the input folder is a folder in the installation package file.
For example, continuing to take the example in step S202 as an example, all input files for executing the target task are traversed, and the input class. Dex, shrunkJavaRes.jar, androidManifest.xml, resources-debug-strap. Ap_file is obtained, where the Resources-debug-strap. Ap_file is the stored binary extraction resource file, that is, the second file.
Further, in a specific optional embodiment, in step S203, all input files for executing the target task are traversed based on the naming manner corresponding to the preset file and the binary extraction file, so as to obtain the binary extraction file corresponding to the first file, where the binary extraction file as the second file includes:
acquiring a naming mode corresponding to a preset original file and a binary extraction file;
reading a first input file for executing a target task;
judging whether the read input file is a binary extraction file or not;
if the read input file is a binary extraction file, determining the file name of an original file corresponding to the read input file based on a naming mode, and taking the file name as the original file name;
comparing the original file name with the file name of the first file to obtain a comparison result;
If the comparison result is that the names are different, reading the next input file, and returning to the step of judging whether the read input file is a binary extraction file or not to continue to execute;
and if the comparison result is that the names are the same, taking the read input file as a binary extraction file corresponding to the first file.
Specifically, among the input files, some files (original files) have corresponding binary extraction files, and these files and their corresponding binary extraction files are named in association with each other according to a preset naming manner.
The binary extraction file refers to a file that is read and written in a binary manner.
The naming mode corresponding to the preset original file and the binary extraction file can be set according to actual needs and stored in the configuration file, when the binary extraction file is obtained through traversing, the naming mode (naming rule) is read from the configuration file and written into the temporary memory, and naming mode data in the temporary memory are called when naming comparison is carried out each time.
It is easy to understand that there is one and only one binary extraction file corresponding to the first file, and thus, the traversal is ended when the binary extraction file corresponding to the first file is found.
S204: and carrying out secondary compression on the second file to obtain a compressed resource file, and replacing the second file with the compressed resource file to obtain an updated input folder.
It should be noted that, each folder in the android installation package is in a compressed state, the second compression means that the folder in which the second file is located is in a compressed state, and the updated input folder is obtained by decompressing the folder in the compressed state first and then compressing the second file therein.
Among the algorithms employed for performing the secondary compression include, but are not limited to, ZIP compression algorithm, lzma2 algorithm, RLE (Run Length Encoding), and the like.
It should be noted that, from the principle of installing an APK in an android device, the APK is installed, and the APK file is decompressed. And changing the suffix name of the compressed APK file into a 'zip' file, and then decompressing the file by using the un zip to check the second file again. The decompressed size of the file is consistent with that of the uncompressed APK, namely, when the APK is installed, the second file is decompressed, and the problem that the compressed APK cannot be installed is avoided. In one embodiment, the second file size is compressed from 380KB to 80KB, and the volume of the entire APK is reduced by 300KB in size.
For a specific implementation process of replacing the second file with the compressed resource file, reference may be made to the description of the subsequent embodiments, and for avoiding repetition, a description is omitted here.
S205: and compressing and packaging folders containing all the input files to obtain compressed android installation package files.
Specifically, all the input files are files for generating an android installation package, and the first file is compressed and packaged to generate a compressed android installation package file APK.
In this embodiment, by monitoring each task node of the android installation package packaging process, a task type corresponding to each task node is obtained, matching detection is performed on the obtained task type and a designated type, a detection result is obtained, if the detection result is that a task of the designated type is detected, the task of the designated type is used as a target task, a resource file corresponding to the target task is obtained and used as a first file, traversing and matching are performed on each file name in an input folder corresponding to an execution target task based on a naming mode corresponding to a preset file and a binary extraction file, a binary extraction file with a name corresponding to the first file is obtained, the binary extraction file is used as a second file, secondary compression is performed on the second file, a compressed resource file is obtained, the second file is replaced by the compressed resource file, an updated input folder is obtained, the installation package file containing the input folder is compressed and packaged, and the compressed installation package file is obtained, so that the binary extraction file which does not affect the installation of an application program is extracted and the second compression package is reduced, and the compression efficiency and the data transmission efficiency are improved.
In a specific optional embodiment, in step S202, a resource file corresponding to the target task is obtained, and the resource file includes:
in the execution stage of the construction, adding a resource file reading task by adding a doFirst method;
after the resource file reading task is executed, generating a debug log containing the resource file name;
and acquiring the resource file names from the debug log, and reading the files corresponding to the resource file names from all the input files to serve as first files.
The doFirst method is to insert a task code before a queue, and the task code is used for realizing a resource file reading task in the embodiment.
The execution stage of the construction, i.e. execution stage, is the third stage of the lifecycle of the gradle execution.
In this embodiment, in the execution stage of the construction, a doFirst method is added to increase a resource file reading task, after the resource file reading task is executed, a debug log containing a resource file name is generated, the resource file name is obtained from the debug log, and files corresponding to the resource file name are read from all input files and used as first files, so that the first files are quickly extracted from the input files, and the efficiency of extracting the first files is improved.
In a specific alternative embodiment, in step S204, replacing the second file with the compressed resource file includes:
writing the compressed resource file into a temporary folder in the same path as the second file;
and deleting the second file, and updating the file name of the compressed resource file to the file name of the second file.
The temporary folder in the same path as the second file refers to a folder in which the second file is located.
In this embodiment, the second file is updated by writing the compressed resource file into the temporary folder along the same path as the second file, further deleting the second file, and updating the file name of the compressed resource file to the file name of the second file.
In a specific optional embodiment, in step S204, performing secondary compression on the second file to obtain a compressed resource file, including:
and performing volume compression on the second file by adopting an Lzma2 algorithm or a Zip algorithm to obtain a compressed resource file.
Specifically, compared with other existing compression algorithms, the Lzma2 algorithm has higher compression rate and efficiency, the Zip algorithm is lossless compression, and according to actual needs, the Lzma2 algorithm or the Zip algorithm is adopted to compress the volume of the second file, so that secondary compression of the second file is realized, and the reduction of the file volume is facilitated.
In a specific optional implementation manner, comparing the original file name with the file name of the first file to obtain a comparison result includes:
reading the character length of the original file name as a first length, and reading the file name of the first file as a second length;
if the first length is different from the second length, determining that the comparison result is different in name;
if the first length is the same as the second length, comparing the characters at each position in the sequence from front to back;
if the characters at any position are different, the comparison is terminated, the comparison result is determined to be different in name, and if the characters at each position are the same, the comparison result is determined to be the same in name.
In this embodiment, by comparing according to the character lengths, the original files with different lengths are directly removed, so as to speed up the comparison and improve the comparison efficiency.
In a specific optional embodiment, before step S205, before compressing and packaging folders including all input files to obtain a compressed android installation package file, the android installation package compression method further includes:
In the construction process, unreferenced resource files in the res folder and the drawable folder are cleaned, and picture resources in the res folder and the drawable folder are subjected to lossless compression, so that updated res folder and updated drawable folder are obtained.
The unreferenced resource file refers to a file which exists in the res folder and the portable folder but is unused in the code directory.
In the embodiment, in the construction process, unreferenced resource files in the res folder and the drawable folder are cleaned, and picture resources in the res folder and the drawable folder are subjected to lossless compression, so that the updated res folder and the updated drawable folder are obtained, cleaning and picture compression of redundant files are realized, the volumes of the res folder and the drawable folder are reduced, and the volume of the android installation package is reduced.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present invention.
Fig. 3 shows a schematic block diagram of an android installation package compression apparatus in one-to-one correspondence with the android installation package compression method of the above embodiment. As shown in fig. 3, the android installation package compressing apparatus includes a task node monitoring module 31, a first file obtaining module 32, a second file obtaining module 33, a second file updating module 34, and an installation package generating module 35. The functional modules are described in detail as follows:
The task node monitoring module 31 is configured to monitor each task node of the android installation package packaging process, obtain a task type corresponding to each task node, and perform matching detection on the obtained task type and a specified type to obtain a detection result;
the first file obtaining module 32 is configured to take a task of a specified type as a target task if the detection result is that the task of the specified type is detected, and obtain a resource file corresponding to the target task as a first file;
the second file obtaining module 33 is configured to perform traversal matching on each file name in an input folder for executing the target task based on a naming manner corresponding to the preset file and the binary extraction file, so as to obtain a binary extraction file with a name corresponding to the first file, where the input folder is a folder in the installation package file;
a second file updating module 34, configured to perform secondary compression on the second file to obtain a compressed resource file, and replace the second file with the compressed resource file to obtain an updated input folder;
the installation package generating module 35 is configured to compress and package the installation package file containing the input folder, so as to obtain a compressed android installation package file.
Optionally, the first file acquisition module 32 includes:
the task construction unit is used for adding a resource file reading task by adding a doFirst method in the construction execution stage;
the system comprises a log generating unit, a resource file reading unit and a resource file reading unit, wherein the log generating unit is used for generating a debugging log containing the name of a resource file after a resource file reading task is executed;
the file extraction unit is used for obtaining the resource file names from the debug log, and reading the files corresponding to the resource file names from all the input files to serve as first files.
Optionally, the second file acquisition module 33 includes:
the naming mode acquisition unit is used for acquiring naming modes corresponding to preset files and binary extraction files;
an input file reading unit for reading a first input file for executing a target task;
the file type judging unit is used for judging whether the read input file is a binary extraction file or not;
the original name acquisition unit is used for determining the file name of the original file corresponding to the read input file based on the naming mode if the read input file is a binary extraction file, and taking the file name as the original file name;
the name comparison unit is used for comparing the original file name with the file name of the first file to obtain a comparison result;
The loop iteration unit is used for reading the next input file if the comparison results are different in name, and returning to the step of judging whether the read input file is a binary extraction file or not to continue execution;
and the result determining unit is used for taking the read input file as a binary extraction file corresponding to the first file if the comparison result is the same in name.
Optionally, the name comparing unit includes:
a length reading subunit, configured to read a character length of an original file name, as a first length, and read a file name of a first file, as a second length;
the first result determining subunit is configured to determine that the comparison result is different in name if the first length is different from the second length;
a second result determining subunit, configured to compare the characters at each position in the front-to-back order if the first length is the same as the second length;
and the third result determining subunit is used for terminating the comparison if the characters at any position are different, determining that the comparison results are different in name, and determining that the comparison results are the same in name if the characters at each position are the same.
Optionally, the second file update module 34 includes:
A file writing unit for writing the compressed resource file into a temporary folder having the same path as the second file;
and the file replacing unit is used for deleting the second file and updating the file name of the compressed resource file into the file name of the second file.
Optionally, the android installation package compression device further includes:
the file cleaning and compressing module is used for cleaning unreferenced resource files in the res folder and the drawable folder in the construction process, and carrying out lossless compression on picture resources in the res folder and the drawable folder to obtain an updated res folder and an updated drawable folder.
For specific limitations of the android installation package compression device, reference may be made to the above limitation of the android installation package compression method, and no further description is given here. The modules in the android installation package compression device can be all or partially realized by software, hardware and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In order to solve the technical problems, the embodiment of the application also provides computer equipment. Referring specifically to fig. 4, fig. 4 is a basic structural block diagram of a computer device according to the present embodiment.
The computer device 4 comprises a memory 41, a processor 42, a network interface 43 communicatively connected to each other via a system bus. It is noted that only a computer device 4 having a component connection memory 41, a processor 42, a network interface 43 is shown in the figures, but it is understood that not all of the illustrated components are required to be implemented and that more or fewer components may be implemented instead. It will be appreciated by those skilled in the art that the computer device herein is a device capable of automatically performing numerical calculations and/or information processing in accordance with predetermined or stored instructions, the hardware of which includes, but is not limited to, microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASICs), programmable gate arrays (fields-Programmable Gate Array, FPGAs), digital processors (Digital Signal Processor, DSPs), embedded devices, etc.
The computer equipment can be a desktop computer, a notebook computer, a palm computer, a cloud server and other computing equipment. The computer equipment can perform man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch pad or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or D interface display memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage 41 may be an internal storage unit of the computer device 4, such as a hard disk or a memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like, which are provided on the computer device 4. Of course, the memory 41 may also comprise both an internal memory unit of the computer device 4 and an external memory device. In this embodiment, the memory 41 is generally used to store an operating system and various application software installed on the computer device 4, such as program codes compressed by an android installation package. Further, the memory 41 may be used to temporarily store various types of data that have been output or are to be output.
The processor 42 may be a central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is configured to execute a program code stored in the memory 41 or process data, such as a program code for executing control of an electronic file.
The network interface 43 may comprise a wireless network interface or a wired network interface, which network interface 43 is typically used for establishing a communication connection between the computer device 4 and other electronic devices.
The present application also provides another embodiment, namely, a computer readable storage medium, where an interface display program is stored, where the interface display program is executable by at least one processor, so that the at least one processor performs the steps of the android installation package compression method as described above.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present application.
The application is operational with numerous general purpose or special purpose computer system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
It is apparent that the above-described embodiments are only some embodiments of the present application, but not all embodiments, and the preferred embodiments of the present application are shown in the drawings, which do not limit the scope of the patent claims. This application may be embodied in many different forms, but rather, embodiments are provided in order to provide a thorough and complete understanding of the present disclosure. Although the application has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that modifications may be made to the embodiments described in the foregoing description, or equivalents may be substituted for elements thereof. All equivalent structures made by the content of the specification and the drawings of the application are directly or indirectly applied to other related technical fields, and are also within the scope of the application.

Claims (8)

1. The android installation package compression method is characterized by comprising the following steps of:
monitoring each task node of the android installation package packaging flow, obtaining a task type corresponding to each task node, and carrying out matching detection on the obtained task type and a designated type to obtain a detection result;
if the detection result is that a task of a specified type is detected, the task of the specified type is taken as a target task, and a resource file corresponding to the target task is obtained and taken as a first file;
traversing and matching each file name in an input folder for executing the target task based on a naming mode corresponding to a preset file and a binary extraction file to obtain a binary extraction file with a file name corresponding to the first file name as a second file, wherein the input folder is a folder in an installation package file;
traversing file names in an input folder for executing the target task based on a naming mode corresponding to a preset file and a binary extraction file to obtain the binary extraction file with the name corresponding to the first file, wherein the specific steps for serving as a second file comprise:
Acquiring a naming mode corresponding to a preset file and a binary extraction file corresponding to the preset file, wherein the file name of the preset file and the file name of the binary extraction file are named according to the naming mode preset;
reading a first input file for executing the target task;
judging whether the read input file is a binary extraction file or not; if the read input file is a binary extraction file, determining the file name of an original file corresponding to the read input file based on the naming mode, and taking the file name as the original file name;
comparing the original file name with the file name of the first file to obtain a comparison result;
if the comparison result shows that the file names are different, reading the next input file, and returning to the step of judging whether the read input file is a binary extraction file or not for continuous execution;
if the comparison result shows that the file names are the same, the read input file is used as a binary extraction file corresponding to the first file;
performing secondary compression on the second file to obtain a compressed resource file, and replacing the second file with the compressed resource file to obtain an updated input folder;
Compressing and packaging the installation package file containing the updated input folder to obtain a compressed android installation package file;
before compressing and packaging the folders containing all the input files to obtain the compressed android installation package file, the specific steps of the android installation package compression method further comprise:
in the construction process, unreferenced resource files in the res folder and the drawable folder are cleaned, and picture resources in the res folder and the drawable folder are subjected to lossless compression, so that updated res folder and updated drawable folder are obtained.
2. The android installation package compression method of claim 1, wherein the android installation package is monitored using a project automation construction tool gradle.
3. The android installation package compression method according to claim 2, wherein the obtaining the resource file corresponding to the target task as the first file includes:
in the execution stage of the construction, adding a resource file reading task by adding a doFirst method;
after the resource file reading task is executed, generating a debug log containing the resource file name;
And acquiring a resource file name from the debug log, and reading a file corresponding to the resource file name from all the input files as a first file.
4. The android installation package compression method of claim 1, wherein replacing the second file with the compressed resource file to obtain an updated input folder comprises:
writing the compressed resource file into a temporary folder in the same path as the second file;
and deleting the second file, and updating the file name of the compressed resource file to the file name of the second file to obtain an updated input folder.
5. The android installation package compression method according to any one of claims 1 to 4, wherein comparing the original file name with the file name of the first file to obtain a comparison result includes:
reading the character length of the original file name as a first length, and reading the character length of the file name of the first file as a second length;
if the first length is different from the second length, determining that the comparison result is that the file names are different;
If the first length is the same as the second length, comparing the characters at each position in the sequence from front to back;
if the characters at any position are different, the comparison is terminated, the comparison result is determined to be different in name, and if the characters at each position are the same, the comparison result is determined to be the same in file name.
6. An android installation package compression device, comprising:
the task node monitoring module is used for monitoring each task node of the android installation package packaging flow, obtaining a task type corresponding to each task node, and carrying out matching detection on the obtained task type and a designated type to obtain a detection result;
the first file acquisition module is used for taking the task of the appointed type as a target task and acquiring a resource file corresponding to the target task as a first file if the detection result is that the task of the appointed type is detected;
the second file acquisition module is used for performing traversal matching on each file name in an input folder for executing the target task based on a naming mode corresponding to a preset file and a binary extraction file to obtain a binary extraction file with a name corresponding to the first file as a second file, wherein the input folder is a folder in an installation package file;
The second file updating module is used for carrying out secondary compression on the second file to obtain a compressed resource file, and replacing the second file with the compressed resource file to obtain an updated input folder;
the installation package generation module is used for compressing and packaging the installation package file containing the updated input folder to obtain a compressed android installation package file;
the second file acquisition module includes:
a naming mode obtaining unit, configured to obtain a naming mode corresponding to a preset file and a binary extraction file corresponding to the preset file, where a file name of the preset file and a file name of the binary extraction file are named according to the naming mode set in advance;
an input file reading unit for reading a first input file for executing the target task;
the file type judging unit is used for judging whether the read input file is a binary extraction file or not; if the read input file is a binary extraction file, determining the file name of an original file corresponding to the read input file based on the naming mode, and taking the file name as the original file name;
The name comparison unit is used for comparing the original file name with the file name of the first file to obtain a comparison result;
the loop iteration unit is used for reading the next input file if the comparison result is that the file names are different, and returning to the step of judging whether the read input file is a binary extraction file for continuous execution;
the result determining unit is used for taking the read input file as a binary extraction file corresponding to the first file if the comparison result is that the file names are the same;
the android installation package compression device comprises:
the file cleaning and compressing module is used for cleaning unreferenced resource files in the res folder and the drawable folder in the construction process, and carrying out lossless compression on picture resources in the res folder and the drawable folder to obtain an updated res folder and an updated drawable folder.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the android installation package compression method of any one of claims 1 to 5 when the computer program is executed.
8. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the android installation package compression method of any one of claims 1 to 5.
CN202110975917.3A 2021-08-24 2021-08-24 Android installation package compression method and device, computer equipment and storage medium Active CN113656044B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110975917.3A CN113656044B (en) 2021-08-24 2021-08-24 Android installation package compression method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110975917.3A CN113656044B (en) 2021-08-24 2021-08-24 Android installation package compression method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113656044A CN113656044A (en) 2021-11-16
CN113656044B true CN113656044B (en) 2023-09-19

Family

ID=78481834

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110975917.3A Active CN113656044B (en) 2021-08-24 2021-08-24 Android installation package compression method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113656044B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6886161B1 (en) * 2001-05-24 2005-04-26 Nortel Networks Limited Method and data structure for compressing file-reference information
CN112363987A (en) * 2020-11-13 2021-02-12 北京沃东天骏信息技术有限公司 File compression method and device, file loading method and device and electronic equipment
CN112765112A (en) * 2021-01-22 2021-05-07 苏州浪潮智能科技有限公司 Installation package packing and unpacking method
CN113282300A (en) * 2021-06-28 2021-08-20 中国平安人寿保险股份有限公司 Volume optimization method, device, equipment and storage medium for application installation package

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7305376B2 (en) * 2003-10-23 2007-12-04 Microsoft Corporation Multiple language-dependent resources compacted into a single resource file
CN106445608A (en) * 2010-01-27 2017-02-22 中兴通讯股份有限公司 Software installation pack installing method and installing device
US9170804B2 (en) * 2012-07-05 2015-10-27 Nokia Technologies Oy Method and apparatus for modifying compressed files
US9785429B2 (en) * 2015-02-27 2017-10-10 Lenovo (Singapore) Pte. Ltd. Efficient deployment of thin client applications to end user

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6886161B1 (en) * 2001-05-24 2005-04-26 Nortel Networks Limited Method and data structure for compressing file-reference information
CN112363987A (en) * 2020-11-13 2021-02-12 北京沃东天骏信息技术有限公司 File compression method and device, file loading method and device and electronic equipment
CN112765112A (en) * 2021-01-22 2021-05-07 苏州浪潮智能科技有限公司 Installation package packing and unpacking method
CN113282300A (en) * 2021-06-28 2021-08-20 中国平安人寿保险股份有限公司 Volume optimization method, device, equipment and storage medium for application installation package

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
计算机互联网络中的数据压缩技术应用;王平, 朱雪梅;计算机工程(第12期);第158-159、191页 *

Also Published As

Publication number Publication date
CN113656044A (en) 2021-11-16

Similar Documents

Publication Publication Date Title
CN109976761B (en) Software development kit generation method and device and terminal equipment
CN110825619A (en) Automatic generation method and device of interface test case and storage medium
CN112491602B (en) Behavior data monitoring method and device, computer equipment and medium
CN112015430A (en) JavaScript code translation method and device, computer equipment and storage medium
CN110688096B (en) Method and device for constructing application program containing plug-in, medium and electronic equipment
CN114416481A (en) Log analysis method, device, equipment and storage medium
CN114398673A (en) Application compliance detection method and device, storage medium and electronic equipment
CN117033249A (en) Test case generation method and device, computer equipment and storage medium
CN113268245A (en) Code analysis method, device and storage medium
CN106406923A (en) Processing method and device of dynamic library file
CN113656044B (en) Android installation package compression method and device, computer equipment and storage medium
CN115080114B (en) Application program transplanting processing method, device and medium
CN109828759B (en) Code compiling method, device, computer device and storage medium
CN116578282A (en) Code generation method, device, electronic equipment and medium
CN113778515B (en) Method and device for determining program package change information
CN115509913A (en) Software automation test method, device, machine readable medium and equipment
CN112965721A (en) Android-based project compiling method and device, computer equipment and storage medium
CN113110846A (en) Method and device for acquiring environment variable
CN116302847B (en) Dynamic acquisition method and device of abnormal information, computer equipment and medium
CN116028108B (en) Method, device, equipment and storage medium for analyzing dependent package installation time
CN114756244A (en) Log processing method and device, computer equipment and storage medium
CN114995858A (en) Method and system for detecting compatibility of upgrade package
CN105224367A (en) A kind of installation method of software and device
CN117827624A (en) Function test method, device and storage medium
CN116595590A (en) Data desensitization method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant