Skip to content

Commit b9cdb3c

Browse files
pcmenkemeta-codesync[bot]
authored andcommitted
Add 16KB alignment for redex
Summary: Android 15+ devices with 16KB page sizes require native shared libraries to be aligned to 16KB boundaries within APKs. This adds a `--page-align-libs-16kb` flag to redex that passes `-P 16` to zipalign, aligning uncompressed .so files to 16KB boundaries instead of the legacy 4KB alignment (`-p`). Reviewed By: agampe Differential Revision: D91703620 fbshipit-source-id: a1d32890824c5214771e28adb58c7c3e58cd6c4b
1 parent 41c4468 commit b9cdb3c

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

redex.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# pyre-strict
88

99
import argparse
10+
import enum
1011
import errno
1112
import glob
1213
import json
@@ -419,22 +420,35 @@ def run() -> None:
419420
raise err
420421

421422

423+
class PageAlignment(enum.Enum):
424+
NONE = ()
425+
PAGE_4KB = ("-p",)
426+
PAGE_16KB = ("-P", "16")
427+
428+
@classmethod
429+
def from_args(cls, page_align: bool, page_align_16kb: bool) -> "PageAlignment":
430+
if page_align_16kb:
431+
return cls.PAGE_16KB
432+
if page_align:
433+
return cls.PAGE_4KB
434+
return cls.NONE
435+
436+
422437
def zipalign(
423438
unaligned_apk_path: str,
424439
output_apk_path: str,
425440
ignore_zipalign: bool,
426-
page_align: bool,
441+
page_align: PageAlignment = PageAlignment.NONE,
427442
) -> None:
428443
# Align zip and optionally perform good compression.
429444
try:
430445
zipalign = [
431446
find_zipalign(),
447+
*page_align.value,
432448
"4",
433449
unaligned_apk_path,
434450
output_apk_path,
435451
]
436-
if page_align:
437-
zipalign.insert(1, "-p")
438452

439453
p = subprocess.Popen(zipalign, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
440454
out, _ = p.communicate()
@@ -534,7 +548,7 @@ def align_and_sign_output_apk(
534548
signing_config: typing.Optional[SigningConfig],
535549
ignore_zipalign: bool,
536550
ignore_apksigner: bool,
537-
page_align: bool,
551+
page_align: PageAlignment = PageAlignment.NONE,
538552
) -> None:
539553
if isfile(output_apk_path):
540554
os.remove(output_apk_path)
@@ -754,6 +768,11 @@ def arg_parser() -> argparse.ArgumentParser:
754768
action="store_true",
755769
help="Preserve 4k page alignment for uncompressed libs",
756770
)
771+
parser.add_argument(
772+
"--page-align-libs-16kb",
773+
action="store_true",
774+
help="Use 16KB page alignment for uncompressed libs (required for Android 15+ devices)",
775+
)
757776

758777
parser.add_argument(
759778
"--side-effect-summaries", help="Side effect information for external methods"
@@ -1632,6 +1651,10 @@ def finalize_redex(state: State) -> None:
16321651
_assert_val(state.zip_manager).__exit__(*sys.exc_info())
16331652

16341653
with BuckPartScope("Redex::AlignAndSign", "Aligning and signing"):
1654+
page_align = PageAlignment.from_args(
1655+
state.args.page_align_libs,
1656+
state.args.page_align_libs_16kb,
1657+
)
16351658
align_and_sign_output_apk(
16361659
_assert_val(state.zip_manager).output_apk,
16371660
state.args.out,
@@ -1642,7 +1665,7 @@ def finalize_redex(state: State) -> None:
16421665
extract_signing_args(state.args, fail_on_error=False),
16431666
state.args.ignore_zipalign,
16441667
state.args.ignore_apksigner,
1645-
state.args.page_align_libs,
1668+
page_align,
16461669
)
16471670

16481671
with BuckPartScope("Redex::OutputDir", "Arranging output dir"):

0 commit comments

Comments
 (0)