Skip to content

support Android SDK build-tools apksigner v35/v36; fix #96 - #109

Open
XenoAmess wants to merge 4 commits into
sisong:masterfrom
xenoamess-fork:master
Open

support Android SDK build-tools apksigner v35/v36; fix #96#109
XenoAmess wants to merge 4 commits into
sisong:masterfrom
xenoamess-fork:master

Conversation

@XenoAmess

Copy link
Copy Markdown

Summary

Fix #96: support Android SDK build-tools apksigner v35 (and later v36).

Root cause

apksigner v35+ re-aligns uncompressed ZIP entries while signing and writes a
dedicated 0xd935 alignment extra field only in the local file header (the
central directory keeps the pre-signing extra fields). This breaks the
local header extra == central directory extra invariant that ZipPatch's
reconstruction relies on, so the patched APK was not byte-by-byte equal to the
released (re-signed) APK.

Fix

  • ZipDiff now saves the target's local file header info (local header
    offset + local header extra field, per entry) into the diff, using a new
    diff format tag ZiPat2&, whenever the local header extra differs from
    the central directory extra (i.e. apksigner v35/v36-signed targets).
  • ZipPatch writes those local headers byte-verbatim at their saved offsets,
    so the patched APK is byte-by-byte equal.
  • Old ZiPat1& diffs stay unchanged for v34 / not-re-signed targets, so old
    ZipPatch keeps working for them; new v1.9.0+ ZipPatch reads both formats.
    Old ZipPatch cleanly rejects ZiPat2& (version check), never silently
    corrupting.
  • Also fix UnZipper_getHugePageAlign for the v35 layout (local header length
    derived when CD extra != local extra).

Tests

  • New builds/apksigner_roundtrip_test.sh + CI job apksigner-roundtrip-test
    running ApkNormalized -> apksigner -> ZipDiff -> ZipPatch round-trips for
    build-tools 34.0.0 / 35.0.0 / 36.1.0, verifying the patched APK is
    byte-by-byte equal and its signature verifies.
    • v34: diff stays ZiPat1& (legacy, old tools compatible)
    • v35/v36: diff uses ZiPat2& (new format)

Backward compatibility matrix is documented in docs/issue-96-fix-plan.md.

ZipDiff saves the target's local file header info (local header offset +
local header extra field, per entry) into a new diff format tag ZiPat2&,
whenever the local header extra differs from the central directory extra
(apksigner v35 writes a 0xd935 alignment extra field only in the local
header when re-aligning uncompressed files). ZipPatch then writes local
headers byte-verbatim at their saved offsets, so the patched apk is
byte-by-byte equal for apksigner v35 signed apks.

Old ZiPat1& diffs stay unchanged for v34/unaligned targets and remain
readable by old ZipPatch; new v1.9.0 ZipPatch reads both formats.
Also fix UnZipper_getHugePageAlign for the v35 layout and add a
v34/v35 apksigner round-trip test to CI.
@XenoAmess

Copy link
Copy Markdown
Author

do you have any ohter test cases we shall cover for this? I can also try adding them into the ci.

@sisong

sisong commented Aug 5, 2026

Copy link
Copy Markdown
Owner

非常感谢你的PR,它解决了库对新版本apksigner的兼容问题,这对有需求或新采纳这个方案的团队很有帮助。
但这个修改对旧的patcher不兼容,当然这也是比较容易想到的直接解决问题的方案。

我也考虑过修复这个和apksigner的兼容问题,但因为要求升级patcher端,所以就想对ApkDiffPatch进行一次更大范围的更新(v2.0),一并解决本库已知的其他设计问题:

  1. patcher端解除对zip格式或apk签名的耦合 (现在和zip格式、apk签名的耦合过于严重)
  2. patcher端在多线程并行时更快,并且内存占用可控 (最大内存占用控制在 threadNum x O(1); 现在是threadNum x O(EntryFileSize))
  3. ApkNormalized 标准化apk时支持 libdeflate 压缩,从而patch还原时可以更快(推荐)或者apk包更小(不推荐)。
  4. 尝试支持对 arm64-v8a和armeabi-v7a的.so文件、安卓.dex文件进行针对性的优化(反汇编),用以得到更小的补丁。

@XenoAmess

Copy link
Copy Markdown
Author

非常感谢你的PR,它解决了库对新版本apksigner的兼容问题,这对有需求或新采纳这个方案的团队很有帮助。 但这个修改对旧的patcher不兼容,当然这也是比较容易想到的直接解决问题的方案。

我也考虑过修复这个和apksigner的兼容问题,但因为要求升级patcher端,所以就想对ApkDiffPatch进行一次更大范围的更新(v2.0),一并解决本库已知的其他设计问题:

  1. patcher端解除对zip格式或apk签名的耦合 (现在和zip格式、apk签名的耦合过于严重)
  2. patcher端在多线程并行时更快,并且内存占用可控 (最大内存占用控制在 threadNum x O(1); 现在是threadNum x O(EntryFileSize))
  3. ApkNormalized 标准化apk时支持 libdeflate 压缩,从而patch还原时可以更快(推荐)或者apk包更小(不推荐)。
  4. 尝试支持对 arm64-v8a和armeabi-v7a的.so文件、安卓.dex文件进行针对性的优化(反汇编),用以得到更小的补丁。

(原来这边说中文啊!)
很期待!加油喵!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support Android sdk build-tools apksigner v35

2 participants