Skip to content

Store native libraries uncompressed and page-aligned - #111

Open
AbhinavKrShukla wants to merge 1 commit into
google:mainfrom
AbhinavKrShukla:store-native-libs-uncompressed-and-page-aligned
Open

Store native libraries uncompressed and page-aligned#111
AbhinavKrShukla wants to merge 1 commit into
google:mainfrom
AbhinavKrShukla:store-native-libs-uncompressed-and-page-aligned

Conversation

@AbhinavKrShukla

Copy link
Copy Markdown

android:extractNativeLibs="false" lets the platform mmap a native library
straight out of the APK/AAB instead of extracting a copy to app-private
storage at install time, but it only works if the library's zip entry is
stored (not deflated) and its data starts on a page boundary. Today every
entry except resources.arsc goes through the Deflated path with 4-byte
alignment, so that manifest flag isn't reachable.

This adds native-library detection matching both the APK layout
(lib/<abi>/*.so) and the AAB base-module layout (base/lib/<abi>/*.so,
kept generic instead of hardcoding known ABI names) and stores those
entries uncompressed with 16 KiB alignment — large enough to satisfy both
the traditional 4 KiB page size and the 16 KiB page size newer devices
require.

Non-native-library files are unaffected: resources.arsc keeps its
existing stored/4-byte-aligned handling, everything else still deflates.

Tested:

  • 4 new unit tests in pack-zip (compression method, page alignment,
    path-matching edge cases for both APK and AAB layouts)
  • Full workspace cargo test --workspace --lib --bins passes unmodified
    (the one pre-existing pack-api doctest failure is unrelated — it fails
    identically on main before this change)
  • cargo +nightly fmt --check clean
  • Verified against a real downstream consumer: repacked and re-signed with
    this branch, output still passes real apksigner verify (v2+v3),
    zipalign -c, and aapt2 dump packagename

android:extractNativeLibs="false" lets the platform mmap a native library
straight out of the APK/AAB instead of extracting a copy to app-private
storage at install time, but it only works if the library's zip entry is
stored (not deflated) and its data starts on a page boundary. Today every
entry except resources.arsc goes through the Deflated path with 4-byte
alignment, so that manifest flag isn't reachable.

This adds a native-library detection matching both the APK layout
(lib/<abi>/*.so) and the AAB base module layout (base/lib/<abi>/*.so,
kept generic instead of hardcoding known ABI names) and stores those
entries uncompressed with 16 KiB alignment - large enough to satisfy
both the traditional 4 KiB page size and the 16 KiB page size newer
devices require, so callers don't need to pick per-target-device.

Non-native-library files are unaffected: resources.arsc keeps its
existing stored/4-byte-aligned handling, everything else still deflates.
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.

1 participant