Skip to content

Commit fa47c0d

Browse files
A Googlercopybara-github
authored andcommitted
Use 16 KB options for zipalign.
When using Android build tools version 35.0.0-rc3 or newer, use `-P 16` with `zipalign` instead of `-p 4`. This change is applied in both `mobile_install` and `apk_packaging` rules. #417 PiperOrigin-RevId: 826576032 Change-Id: Ifa58aed4d4390d26490685ea43da36716cec6d0e
1 parent 4ae41c4 commit fa47c0d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mobile_install/apks.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ def _zipalign_sign(ctx, unsigned_apk, signed_apk, debug_signing_keys, debug_sign
206206
" --deterministic-dsa-signing true" +
207207
" --provider-class org.bouncycastle.jce.provider.BouncyCastleProvider")
208208

209-
# zipalign -p 4 input.apk output.apk will align the apk in a 4k boundary.
209+
# note zipalign usage:
210+
# https://cs.android.com/android/platform/superproject/main/+/main:build/make/tools/zipalign/ZipAlignMain.cpp
211+
210212
cmd = """
211213
zipalign=$1
212214
unsigned_apk=$2
@@ -216,7 +218,7 @@ signing_params=$5
216218
signed_apk=$6
217219
tmp_dir=$(mktemp -d)
218220
tmp_apk="${tmp_dir}/zipaligned.apk"
219-
${zipalign} -p 4 ${unsigned_apk} ${tmp_apk}
221+
${zipalign} -P 16 4 ${unsigned_apk} ${tmp_apk}
220222
${jvm} -jar ${apk_signer} sign ${signing_params} --out ${signed_apk} ${tmp_apk}
221223
"""
222224
ctx.actions.run_shell(

rules/apk_packaging.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ def _zipalign_apk(
298298
toolchain_type = None):
299299
""" Zipaligns an unsigned apk."""
300300
args = ctx.actions.args()
301-
args.add("-p", "4")
301+
302+
# note usage: https://cs.android.com/android/platform/superproject/main/+/main:build/make/tools/zipalign/ZipAlignMain.cpp
303+
args.add("-P", "16")
304+
args.add("4")
302305
args.add(in_apk)
303306
args.add(out_apk)
304307

0 commit comments

Comments
 (0)