About the author: content partner and technologist, building a 10 million daily app from scratch.
Focused on sharing original series of articles in various fields , specializing in java back-end, mobile development, business real estate, artificial intelligence and so on, I hope you have more support.
catalogs
I. Introduction
We continue to summarize our learningbasics, warming up to the past.
This article documents the introduction and use of the android etc1 tool.
This article documents the introduction and use of the android zipalign command.
Two, etc1tool
etc1tool is a command line utility that can be used to encode PNG images into the ETC1 Compression Standard Format (PKM) and decode ETC1 compressed images back into PNG.
Simply put, png and pkm image formats are converted to each other.
Files in pkm format in android can be read in the assets directory.
2.1. Usage
etc1tool infile [--help | --encode | --encodeNoHeader | --decode] [--showDifference
diff-file] [-o outfile]
options (as in computer software settings) | clarification |
---|---|
infile | The input file to be compressed. |
–help | Outputs usage information. |
–encode | Creates an ETC1 file from a PNG file. If no mode is specified, this will be the default mode for this tool. |
–encodeNoHeader | Creates the original ETC1 data file (without headers) from a PNG file. |
–decode | Creates a PNG file from an ETC1 file. |
–showDifference diff-file | Writes the difference between the original image and the encoded image to diff-file. this option is only valid when encoding. |
-o outfile | Specifies the name of the output file. If outfile is not specified, the name of the output file will consist of the name of the input file with the appropriate suffix (.pkm or .png). |
III. zipalign
zipalign is a zip archive alignment tool that helps ensure that all uncompressed files in an archive are aligned relative to the beginning of the file.
This is done automatically if you build with Android Studio using the Android Gradle Plugin (AGP).
The following section focuses on the use of custom build systems:
3.1 Utilization
If your APK contains shared libraries (.so files), use -p to make sure they are aligned with the 4KiB page boundaries appropriate for mmap(2).
For other files (whose alignment is determined by zipalign’s mandatory alignment parameter), Android Studio will align to 4 bytes on 32-bit and 64-bit systems.
To align infile.apk and save it as outfile.apk, run the following command:
zipalign -p -f -v 4 infile.apk outfile.apk
To verify the alignment of existing.apk, use the following command. If you are building with Android Studio or AGP, you should use this command to verify that the APK is aligned.
zipalign -c -v 4 existing.apk
options (as in computer software settings) | clarification |
---|---|
-c | Checks alignment only (does not modify the file). |
-f | Overwrite existing output files. |
-h | Displays tool help. |
-p | Aligns uncompressed .so files to pages. |
-v | Detailed output. |
-z | Use Zopfli to recompress. |
IV. Recommended reading
Data Structures and Algorithms