闲来无聊今天研究了下zipalign
,发现Android Studio
貌似打包的时候自带了这个插件功能,就是不需要你去设置,它自动会对齐程序包资源,足以见Android Studio
的强大,但是我们还是得自己知道怎么使用它不是吗?
环境配置(配置zipalign
的环境变量)
如果你没有使用ohmyzsh
~ vim ~/.bashrc
如果使用的是ohmyzsh
vim ~/.zshrc
写入下面的第三个pasth,记住前面的目录是你自己的sdk的路径,别直接复制
#Android sdk
export ANDROID_HOME=/Users/guoyoujin/Library/Android/sdk
export PATH=$PATH:$HOME/Library/Android/sdk/tools:$HOME/Library/Android/sdk/platform-tools
export PATH=$PATH:$HOME/Library/Android/sdk/build-tools/24.0.3
#GOROOT
最后重新载入修改的文件
source ~/.bashrc or source ~/.zshrc
输入zipalign即可查看详细信息了
➜ TxCustomerServices git:(v1.16.1) ✗ zipalign
Zip alignment utility
Copyright (C) 2009 The Android Open Source Project
Usage: zipalign [-f] [-p] [-v] [-z] <align> infile.zip outfile.zip
zipalign -c [-v] <align> infile.zip
<align>: alignment in bytes, e.g. '4' provides 32-bit alignment
-c: check alignment only (does not modify file)
-f: overwrite existing outfile.zip
-p: page align stored shared object files
-v: verbose output
-z: recompress using Zopfli
简单使用
官网简单描述是这样的,相信大家也能看懂
The <alignment> is an integer that defines the byte-alignment boundaries. This must always be 4 (which provides 32-bit alignment) or else it effectively does nothing.
Flags:
-f : overwrite existing outfile.zip
-v : verbose output
-p : outfile.zip should use the same page alignment for all shared object files within infile.zip
-c : confirm the alignment of the given file
对齐程序包资源
zipalign -f -v 4 infile.apk outfile.apk
比对apk是否对齐
zipalign -c -v 4 outfile.apk
输出Verification succesful
则表示已经比对过了