[go: up one dir, main page]

CN113656044A - 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
CN113656044A
CN113656044A CN202110975917.3A CN202110975917A CN113656044A CN 113656044 A CN113656044 A CN 113656044A CN 202110975917 A CN202110975917 A CN 202110975917A CN 113656044 A CN113656044 A CN 113656044A
Authority
CN
China
Prior art keywords
file
installation package
task
folder
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.)
Granted
Application number
CN202110975917.3A
Other languages
Chinese (zh)
Other versions
CN113656044B (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

Images

Classifications

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

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses an android installation package compression method, an android installation package compression device, computer equipment and a storage medium, wherein the method comprises the following steps: monitoring each task node of an android installation package packaging process, obtaining a task type corresponding to each task node, matching and detecting the obtained task type and a specified type, if a task of the specified type is detected, taking the task of the specified type as a target task, obtaining a resource file corresponding to the target task, taking the resource file as a first file, traversing file names in an input folder for executing the target task, obtaining a binary extraction file with the name corresponding to the first file, taking the binary extraction file as a second file, performing secondary compression on the second file, obtaining a compressed resource file, replacing the second file with the compressed resource file, and compressing and packaging installation package files containing updated input folders to obtain compressed android installation package files. 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 an android installation package compression method and device, computer equipment and a storage medium.
Background
Along with the development of mobile communication technology, the application of Android application program is more and more extensive, the developer gives the user through providing Android installation package (APK), the user adopts Android installation package installation application program and uses application program after the installation is successful, but along with the improvement of user's demand, the installation package is bigger and bigger, this results in that the installation package downloads transmission time longer, need consume more network transmission flow resource simultaneously, influence user experience, therefore, need carry out volume compression to Android installation package to improve the efficiency in the installation package data transmission process.
At present, aiming at the volume compression of an android installation package, an automatic packaging tool aapt in the android development package is mainly adopted to determine a file to be compressed which needs to be added into an APK file, and then the file to be compressed is 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 urgently needed.
Disclosure of Invention
The embodiment of the invention provides an android installation package compression method, an android installation package compression device, computer equipment and a storage medium, so that the size of an android installation package is reduced, network transmission flow resources are saved, and the cost is reduced.
In order to solve the above technical problem, an embodiment of the present application provides an android installation package compression method, including:
monitoring each task node of the android installation package packaging process to obtain a task type corresponding to each task node, and performing matching detection on the obtained task type and an appointed type to obtain a detection result;
if the detection result is that the task of the specified type is detected, taking the task of the specified type as a target task, and acquiring a resource file corresponding to the target task as a first file;
traversing and matching each file name in an input folder for executing the target task based on a preset naming mode corresponding to the file and the binary extracted file to obtain the binary extracted file with the 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 the compressed android installation package file.
Optionally, a project automation construction tool gradle is used to monitor the android installation package.
Optionally, the acquiring a resource file corresponding to the target task as the first file includes:
in the construction execution stage, a resource file reading task is added by adding a doFirst method;
after the resource file reading task is executed, generating a debugging log containing the name of the resource file;
and acquiring the resource file name from the debugging log, and reading a file corresponding to the resource file name from all the input files to be used as a first file.
Optionally, the 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.
Optionally, the traversing all the input files executing the target task based on a preset naming mode corresponding to the file and the binary extracted file to obtain the binary extracted file corresponding to the first file, and the traversing all the input files as the second file includes:
acquiring a naming mode corresponding to a preset file and a binary extracted file;
reading a first input file for executing the target task;
judging whether the read input file is a binary extracted file or not; if the read input file is a binary extracted file, determining the file name of an original file corresponding to the read input file as the original file name based on the naming mode;
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 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 for continuous execution;
and if the comparison result shows that the names are the same, taking the read input file as a binary extraction file corresponding to the first file.
Optionally, the 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, terminating the comparison, determining that the comparison result is different in name, and if the characters at each position are the same, determining that the comparison result is the same in name.
Optionally, before the compressing and packaging the folder containing all the input files to obtain the compressed android installation package file, the android installation package compression method further includes:
in the construction process, the unreferenced resource files in the res folder and the drawable folder are cleaned, and the picture resources in the res folder and the drawable folder are subjected to lossless compression to obtain an updated res folder and an updated drawable folder.
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 process to obtain a task type corresponding to each task node, and performing matching detection on the obtained task type and a specified type to obtain a detection result;
the first file acquisition module is used for taking the task of the specified 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 specified type is detected;
the second file acquisition module is used for traversing and matching each file name in an input folder for executing the target task based on a preset naming mode corresponding to a file and a binary extracted file to obtain the binary extracted file with the 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 increasing a resource file reading task by adding a doFirst method in the construction execution stage;
the log generation unit is used for generating a debugging log containing the name of the resource file after the resource file reading task is executed;
and the file extraction unit is used for acquiring the resource file name from the debugging log and reading the file corresponding to the resource file name from all the input files as a first file.
Optionally, the second file updating module includes:
a file writing unit, configured to write the compressed resource file into a temporary folder in 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 a naming mode corresponding to a preset file and a binary extracted file;
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 extracted file or not;
an original name obtaining unit, configured to determine, based on the naming mode, a file name of an original file corresponding to the read input file as an original file name if the read input file is a binary extracted file;
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 cyclic iteration unit is used for reading the next input file if the comparison result shows that the names are different, and returning to the step of judging whether the read input file is a binary extracted file for continuous execution;
and the result determining unit is used for taking the read input file as the binary extraction file corresponding to the first file if the comparison result shows that the names are the same.
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 determination subunit, configured to determine that the comparison result is a name different if the first length is different from the second length;
a second result determination subunit, configured to compare the characters at each position in a sequence 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 result is different in name, and determining that the comparison result is the same in name if the characters at each position are the same.
Optionally, the android installation package compression apparatus further includes:
and the file cleaning and compressing module is used for cleaning the unreferenced resource files in the res folder and the drawable folder in the construction process, and performing lossless compression on the picture resources in the res folder and the drawable folder to obtain the updated res folder and the updated drawable folder.
In order to solve the above technical problem, an embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the above android 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, and when the computer program is executed by a processor, the steps of the above android installation package compression method are implemented.
The android installation package compression method, the device, the computer equipment and the storage medium provided by the embodiment of the invention obtain the task type corresponding to each task node by monitoring each task node of the android installation package packaging process, perform matching detection on the obtained task type and the specified type to obtain a detection result, if the detection result is that the task of the specified type is detected, take the task of the specified type as a target task and obtain a resource file corresponding to the target task as a first file, perform 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 the binary extraction file with the name corresponding to the first file as a second file, perform secondary compression on the second file to obtain a compressed resource file, and replace the second file with the compressed resource file, the updated input folder is obtained, the installation package files containing the input folder are compressed and packaged, the compressed android installation package files are obtained, extraction and secondary compression are carried out on binary extraction files which do not affect application program installation, the installation package volume is reduced, and 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 invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of an android installation package compression method of the present application;
FIG. 3 is a schematic structural diagram of one embodiment of an android installation package compression apparatus according to the application;
FIG. 4 is a schematic block diagram of one embodiment of a computer device according to 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 application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase 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. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
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 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a server that provides various services, for example, a background server that provides support for pages displayed on the terminal devices 101, 102, and 103, and may be an independent server, or a cloud server that provides basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a web service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), and a big data and artificial intelligence platform.
It should be noted that, the android installation package compression method provided in the embodiment of the present application is executed by a server, and accordingly, the android installation package compression device is disposed 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 needs, and the terminal devices 101, 102 and 103 in this embodiment may specifically correspond to an application system in actual production.
Referring to fig. 2, fig. 2 shows an android installation package compression method provided by an embodiment of the present invention, which is described by taking the method as an example when applied to the server in fig. 1, and the embodiment of the present application may acquire and process related data based on an artificial intelligence technology. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence infrastructure generally includes 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 the like.
The detailed description of the present embodiment is as follows:
s201: monitoring each task node of the android installation package packaging process to obtain a task type corresponding to each task node, and performing matching detection on the obtained task type and the specified 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 types are matched and detected with the specified types to obtain a detection result, and the 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: detect configuration files (e.g., android manifest. xml), attribute initialization (e.g., minSdkVersion, and uses-sdk), add referenced resource packages, collect resource files, process overlapping packages, add files to resource tables, compile values resources, assign ids to bag resources, compile resource files, etc.
In the task nodes, part of the task nodes relate to the processing of the compressible resource file, and the task corresponding to the task node relating to the processing of the compressible resource file is used as a task of a specified type, so that the compressible resource file can be acquired through subsequent processing.
Wherein the task of the specified type is used for subsequently acquiring the compressible resource file.
Optionally, a project automation building tool gradle is used to monitor the android installation package.
Wherein, the gradle is a construction tool, the construction of which is based on a JVM-based dynamic language groovy (DSL) for declaring construction and creation tasks and making the dependency management simpler. The lifecycle of the construction Execution of the Gradle includes three phases, which are an Initialization phase Initialization, a Configuration phase Configuration, and an Execution phase Execution. In this embodiment, a task of a specified type is preset, and each task node of the installation package is monitored through the gradle, so that a critical task is quickly screened out.
In this embodiment, adopt the higher construction tool gradle of degree of automation to monitor android installation package, it is comparatively convenient, reduce code development cost and improve and monitor efficiency.
S202: and if the detection result is that the task of the specified type is detected, taking the task of the specified type as a target task, and acquiring a resource file corresponding to the target task as a first file.
Specifically, the task of the specified type is a task having the same type as the preset type, in this embodiment, the specified type is determined based on the environment and the preset element, for example, the preset element is a certain package ", the task of the current channel environment name is added at the beginning, the test environment is a packageDebug, the production environment is a packageRelease, and the task of the specified type is formed, and when the task of the specified type is detected, the resource file corresponding to the task of the specified type is obtained as the first file.
For details, the process of acquiring the first file may refer to the description of the subsequent embodiments, and is not repeated here to avoid repetition.
Optionally, the first file is a resources.
When the APK is packaged to install files, 2 more important files related to resources 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 class, the resources.arsc file is a file for recording mapping information of the resources, for example, the file contains ResTable, pool information indicating header information, thread pool information and character strings, and for example, a picture resource named as image _ src needs to be loaded, and under 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 preset naming mode corresponding to the file and the binary extracted file to obtain the binary extracted 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 an input classes.
Further, in a specific optional implementation manner, in step S203, based on a preset naming mode corresponding to the file and the binary extracted file, all input files for executing the target task are traversed to obtain the binary extracted file corresponding to the first file, and the binary extracted file serving as the second file includes:
acquiring a naming mode corresponding to a preset original file and a binary extracted file;
reading a first input file for executing a target task;
judging whether the read input file is a binary extracted file or not;
if the read input file is a binary extracted file, determining the file name of the original file corresponding to the read input file based on a naming mode, and using 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 names are different, reading the next input file, and returning to the step of judging whether the read input file is a binary extracted file or not to continue execution;
and if the comparison result shows that the names are the same, taking the read input file as a binary extraction file corresponding to the first file.
Specifically, in the input file, some files (original files) have corresponding binary extraction files, and these files are associated with their corresponding binary extraction files in a naming manner set in advance.
The binary extraction file refers to a file which is read and written in a binary mode.
The naming method corresponding to the preset original file and the binary extraction file can be specifically set according to actual needs and stored in a configuration file, when the binary extraction file is obtained through traversal, the naming method (naming rule) is read from the configuration file and written into a temporary memory, and when name comparison is carried out each time, naming method data in the temporary memory is called.
It is easily understood that there is only one binary extraction file corresponding to the first file, and thus, the traversal is finished when the binary extraction file corresponding to the first file is found.
S204: and 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.
It should be noted that each folder in the android installation package is in a compressed state, and secondary compression means that the folder where 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 and then compressing the second file therein.
The algorithms used for performing the second compression include, but are not limited to, a ZIP compression algorithm, an lzma2 algorithm, and rle (run Length encoding).
It should be noted that, from the principle of installing an APK by an android device, the APK is installed, and in fact, the APK file is also decompressed. The second file is reviewed by modifying the compressed APK file with a suffix ". zip" file, and then decompressing the file using unzip. The file and the uncompressed APK have the same size after being decompressed, namely, when the APK is installed, the file of the second file is decompressed, and the problem that the second file cannot be installed after being compressed does not exist. In one embodiment, the second file size is compressed from 380KB to 80KB, and the volume of the entire APK is ultimately reduced by 300 KB.
The specific implementation process of replacing the second file with the compressed resource file may refer to the description of the subsequent embodiments, and is not repeated here to avoid repetition.
S205: and compressing and packaging the folders containing all the input files to obtain the compressed android installation package files.
Specifically, all input files refer to files for generating an android installation package, and the second file is compressed and packaged to generate a compressed android installation package file APK.
In the embodiment, each task node of an android installation package packaging process is monitored to obtain a task type corresponding to each task node, the obtained task type is matched and detected with a specified type to obtain a detection result, 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, a resource file corresponding to the target task is obtained and taken as a first file, each file name in an input folder corresponding to the execution target task is subjected to traversal matching based on a preset naming mode corresponding to the file and a binary extraction file to obtain the binary extraction file of which the name corresponds to the first file and taken as a second file, the second file is subjected to secondary compression to obtain a compressed resource file, the compressed resource file is adopted to replace the second file to obtain an updated input folder, and the installation package file containing the input folder is compressed and packaged, and obtaining the compressed android installation package file, extracting and secondarily compressing the binary extraction file which does not influence the installation of the application program, reducing the volume of the installation package, and improving the compression efficiency and the data transmission efficiency.
In a specific optional implementation manner, in step S202, the obtaining a resource file corresponding to the target task as the first file includes:
in the construction execution stage, a resource file reading task is added by adding a doFirst method;
after the resource file reading task is executed, generating a debugging log containing the name of the resource file;
and acquiring the resource file name from the debugging log, and reading a file corresponding to the resource file name from all input files to be used as a first file.
In the doFirst method, a task code is inserted in front of a queue, and the task code is used for realizing a resource file reading task in the embodiment.
The execution phase of the construction, that is, the execution phase, is the third phase of the lifecycle of the execution of the gradle.
In the embodiment, at the construction execution stage, a resource file reading task is added by adding a doFirst method, after the resource file reading task is executed, a debugging log containing resource file names is generated, the resource file names are obtained from the debugging log, and files corresponding to the resource file names are read from all input files to serve 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 optional 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 with the second file;
and deleting the second file, and updating the file name of the compressed resource file into the file name of the second file.
The temporary folder in the same path with the second file is the folder where the second file is located.
In this embodiment, the compressed resource file is written into the temporary folder in the same path as the second file, so as to delete the second file, and the file name of the compressed resource file is updated to the file name of the second file, thereby updating the second file.
In a specific optional implementation manner, 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 the second file is subjected to volume compression by adopting the Lzma2 algorithm or the Zip algorithm according to actual needs, so that secondary compression of the second file is realized, and reduction of the file volume is facilitated.
In a specific optional embodiment, 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 name of the comparison result is 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 name.
In the embodiment, the comparison is performed according to the character length, the original files with different lengths are directly excluded, the comparison speed is increased, and the comparison efficiency is improved.
In a specific optional implementation manner, before step S205, before performing compression and packaging on a folder containing all input files to obtain a compressed android installation package file, the android installation package compression method further includes:
in the construction process, the unreferenced resource files in the res folder and the drawable folder are cleaned, and the picture resources in the res folder and the drawable folder are subjected to lossless compression to obtain an updated res folder and an updated drawable folder.
The unreferenced resource file refers to a file that exists in the res folder and the drawable folder but is not used in the code directory.
In the embodiment, in the construction process, the unreferenced resource files in the res folder and the drawable folder are cleaned, the image resources in the res folder and the drawable folder are subjected to lossless compression, the updated res folder and the updated drawable folder are obtained, the redundant files are cleaned and the image is compressed, the volumes of the res folder and the drawable folder are reduced, and the size of the android installation package is favorably reduced.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 3 is a schematic block diagram of an android installation package compression device corresponding to the android installation package compression method in the foregoing embodiment one to one. As shown in fig. 3, the android installation package compression device 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 explained in detail as follows:
the task node monitoring module 31 is configured to monitor each task node of the android package packaging process to obtain a task type corresponding to each task node, and perform matching detection on the obtained task type and an appointed type to obtain a detection result;
the first file obtaining module 32 is configured to, if the detection result is that the task of the specified type is detected, take the task of the specified type as a target task, 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 a target task based on a preset naming mode in which a file corresponds to a binary extracted file, to obtain the binary extracted file with the name corresponding to the first file, and to use the binary extracted file as the second file, where the input folder is a folder in an installation package file;
the second file updating module 34 is 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;
and the installation package generating module 35 is configured to compress and package the installation package file including the input folder to obtain a compressed android installation package file.
Optionally, the first file obtaining module 32 includes:
the task construction unit is used for increasing a resource file reading task by adding a doFirst method in the construction execution stage;
the log generation unit is used for generating a debugging log containing the name of the resource file after the resource file reading task is executed;
and the file extraction unit is used for acquiring the resource file name from the debugging log and reading a file corresponding to the resource file name from all input files as a first file.
Optionally, the second file obtaining module 33 includes:
the naming mode acquisition unit is used for acquiring a naming mode corresponding to a preset file and a binary extracted file;
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 extracted file or not;
an original name acquisition unit, configured to determine, based on a naming mode, a file name of an original file corresponding to the read input file as an original file name if the read input file is a binary extracted file;
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 cyclic iteration unit is used for reading the next input file if the comparison result shows that the names are different, and returning to the step of judging whether the read input file is a binary extracted file to continue execution;
and the result determining unit is used for taking the read input file as the binary extraction file corresponding to the first file if the comparison result shows that the names are the same.
Optionally, the name comparison unit includes:
the length reading subunit is used for 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;
a first result determination subunit, configured to determine that the comparison result is that the name is different if the first length is different from the second length;
a second result determination subunit, configured to compare the characters at each position in a sequence 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 name of the comparison result is different, and determining that the name of the comparison result is the same if the characters at each position are the same.
Optionally, the second file updating module 34 includes:
the file writing unit is used for writing the compressed resource file into a temporary folder in the same path with 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 apparatus further includes:
and the file cleaning and compressing module is used for cleaning the unreferenced resource files in the res folder and the drawable folder in the construction process, and performing lossless compression on the picture resources in the res folder and the drawable folder to obtain the updated res folder and the updated drawable folder.
For specific limitations of the android package compression device, see the above limitations on the android package compression method, which are not described herein again. All or part of the modules in the android installation package compression device can be realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In order to solve the technical problem, an embodiment of the present application further provides a computer device. Referring to fig. 4, fig. 4 is a block diagram of a basic structure 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 the computer device 4 having the components connection memory 41, processor 42, network interface 43 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including a 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 memory 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 memory Card (Flash Card), and the like, which are provided on the computer device 4. Of course, the memory 41 may also include both internal and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used for storing an operating system installed in the computer device 4 and various types of application software, such as program codes compressed by an android installation package. Further, the memory 41 may also 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 (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 the program code stored in the memory 41 or process data, such as program code for executing control of an electronic file.
The network interface 43 may comprise a wireless network interface or a wired network interface, and the network interface 43 is generally used for establishing communication connection between the computer device 4 and other electronic devices.
The present application further provides another embodiment, which is to provide a computer-readable storage medium storing an interface display program, where the interface display program is executable by at least one processor to cause the at least one processor to execute the steps of the android package compression method.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
The application is operational with numerous general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type 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 to be understood that the above-described embodiments are merely illustrative of some, but not restrictive, of the broad invention, and that the appended drawings illustrate preferred embodiments of the invention and do not limit the scope of the invention. This application is capable of embodiments in many different forms and is provided for the purpose of enabling a thorough understanding of the disclosure of the application. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields and are within the protection scope of the present application.

Claims (10)

1. An android installation package compression method is characterized by comprising the following steps:
monitoring each task node of the android installation package packaging process to obtain a task type corresponding to each task node, and performing matching detection on the obtained task type and an appointed type to obtain a detection result;
if the detection result is that the task of the specified type is detected, taking the task of the specified type as a target task, and acquiring a resource file corresponding to the target task as a first file;
traversing and matching each file name in an input folder for executing the target task based on a preset naming mode corresponding to the file and the binary extracted file to obtain the binary extracted file with the 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 the compressed android installation package file.
2. The android installation package compression method of claim 1, wherein the android installation package is intercepted with a project automation build tool (GRADLE).
3. The android installation package compression method of claim 2, wherein the obtaining the resource file corresponding to the target task as a first file comprises:
in the construction execution stage, a resource file reading task is added by adding a doFirst method;
after the resource file reading task is executed, generating a debugging log containing the name of the resource file;
and acquiring the resource file name from the debugging log, and reading a file corresponding to the resource file name from all the input files to be used as a first file.
4. The android installation package compression method of claim 1, wherein the replacing the second file with the compressed resource file to obtain the 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 into the file name of the second file to obtain an updated input folder.
5. The android package compression method of any of claims 1 to 4, wherein traversing a file name in an input folder that executes the target task based on a naming manner that a preset file corresponds to a binary extracted file, to obtain the binary extracted file whose name corresponds to the first file, as the second file, comprises:
acquiring a naming mode corresponding to a preset file and a binary extracted file;
reading a first input file for executing the target task;
judging whether the read input file is a binary extracted file or not; if the read input file is a binary extracted file, determining the file name of an original file corresponding to the read input file as the original file name based on the naming mode;
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 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 for continuous execution;
and if the comparison result shows that the names are the same, taking the read input file as a binary extraction file corresponding to the first file.
6. The android installation package compression method of any of claims 1 to 4, wherein comparing the original file name with the file name of the first file to obtain a comparison result comprises:
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, terminating the comparison, determining that the comparison result is different in name, and if the characters at each position are the same, determining that the comparison result is the same in name.
7. The android installation package compression method of any of claims 1 to 4, wherein before the compression and packaging of the folder containing all the input files to obtain the compressed android installation package files, the android installation package compression method further comprises:
in the construction process, the unreferenced resource files in the res folder and the drawable folder are cleaned, and the picture resources in the res folder and the drawable folder are subjected to lossless compression to obtain an updated res folder and an updated drawable folder.
8. An android installation package compression apparatus, comprising:
the task node monitoring module is used for monitoring each task node of the android installation package packaging process to obtain a task type corresponding to each task node, and performing matching detection on the obtained task type and a specified type to obtain a detection result;
the first file acquisition module is used for taking the task of the specified 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 specified type is detected;
the second file acquisition module is used for traversing and matching each file name in an input folder for executing the target task based on a preset naming mode corresponding to a file and a binary extracted file to obtain the binary extracted file with the 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.
9. 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 of claims 1 to 7 when executing the computer program.
10. 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 of claims 1 to 7.
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 true CN113656044A (en) 2021-11-16
CN113656044B 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)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115361369A (en) * 2022-08-12 2022-11-18 中国联合网络通信集团有限公司 Data processing method, device, electronic device, and computer-readable storage medium

Citations (8)

* 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
US20050102253A1 (en) * 2003-10-23 2005-05-12 Microsoft Corporation Resource compaction
US20120159470A1 (en) * 2010-01-27 2012-06-21 Zte Corporation Method and device for generating software installation packet
US20140013006A1 (en) * 2012-07-05 2014-01-09 Nokia Corporation Method and apparatus for modifying compressed files
US20160253170A1 (en) * 2015-02-27 2016-09-01 Lenovo (Singapore) Pte, Ltd. Efficient deployment of thin client applications to end user
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

Patent Citations (8)

* 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
US20050102253A1 (en) * 2003-10-23 2005-05-12 Microsoft Corporation Resource compaction
US20120159470A1 (en) * 2010-01-27 2012-06-21 Zte Corporation Method and device for generating software installation packet
US20140013006A1 (en) * 2012-07-05 2014-01-09 Nokia Corporation Method and apparatus for modifying compressed files
US20160253170A1 (en) * 2015-02-27 2016-09-01 Lenovo (Singapore) Pte, Ltd. Efficient deployment of thin client applications to end user
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
王平, 朱雪梅: "计算机互联网络中的数据压缩技术应用", 计算机工程, no. 12, pages 158 - 159 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115361369A (en) * 2022-08-12 2022-11-18 中国联合网络通信集团有限公司 Data processing method, device, electronic device, and computer-readable storage medium
CN115361369B (en) * 2022-08-12 2024-05-31 中国联合网络通信集团有限公司 Data processing method, device, electronic equipment and computer readable storage medium

Also Published As

Publication number Publication date
CN113656044B (en) 2023-09-19

Similar Documents

Publication Publication Date Title
CN109976761B (en) Software development kit generation method and device and terminal equipment
CN112015430B (en) JavaScript code translation method, device, computer equipment and storage medium
CN112491602A (en) Behavior data monitoring method and device, computer equipment and medium
CN112394908A (en) Method and device for automatically generating embedded point page, computer equipment and storage medium
CN117033249B (en) Test case generation method and device, computer equipment and storage medium
CN112965721B (en) Project compiling method and device based on Android, computer equipment and storage medium
CN113536185A (en) Application page loading method, storage medium and related equipment thereof
CN108415826A (en) Test method, terminal device and the computer readable storage medium of application
CN113869789A (en) Risk monitoring method and device, computer equipment and storage medium
CN112416458A (en) Preloading method and device based on ReactNative, computer equipment and storage medium
CN114416481A (en) Log analysis method, device, device and storage medium
CN115982491A (en) Page updating method and device, electronic equipment and computer readable storage medium
CN112363814B (en) Task scheduling method, device, computer equipment and storage medium
CN112269666B (en) Small program dead link detection method and device, computing device and medium
CN112527386A (en) Application program issuing method and device
CN113419738A (en) Interface document generation method and device and interface management equipment
CN111273980B (en) Interface thread visualization method and device, computer equipment and storage medium
CN113656044B (en) Android installation package compression method and device, computer equipment and storage medium
CN116627778A (en) Service system performance monitoring method and device, computer equipment and storage medium
CN115576624A (en) Programming framework optimization method, system, terminal equipment and storage medium
CN114996616A (en) Information generation method, device and equipment based on browser and storage medium
CN114371886A (en) Front-end frame assembly conversion method and device, computer equipment and storage medium
CN115328764A (en) Test code optimization method and related equipment based on automated test
CN115033240A (en) Processing method and device for error reporting information, computer equipment and storage medium
CN114218191A (en) System function migration method and 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