From 204a233235f342fec65e4f5d1ad4622ff7b59006 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 10 Jun 2026 13:58:24 -0400 Subject: [PATCH] Some improvements to apkdiff. --- reproducible-builds/README.md | 1 + reproducible-builds/apkdiff/apkdiff.py | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/reproducible-builds/README.md b/reproducible-builds/README.md index e4ab951267..ef3aa6cbb4 100644 --- a/reproducible-builds/README.md +++ b/reproducible-builds/README.md @@ -34,6 +34,7 @@ Before you begin, ensure you have the following installed: - `uv` - `adb` ([link](https://developer.android.com/tools/adb)) - `bundletool` ([link](https://github.com/google/bundletool/releases)) +- `aapt2` (included with the Android SDK Build Tools, [link](https://developer.android.com/tools/aapt2)) You will also need to have Developer Options and USB Debugging enabled on your Android device. You can find instructions to do so [here](https://developer.android.com/studio/debug/dev-options). After the prerequisites are installed and the dev options are enabled, you can connect your Android device to your computer and run the `adb devices` command in your terminal. If everything has been set up correctly, your Android device will show up in the list. diff --git a/reproducible-builds/apkdiff/apkdiff.py b/reproducible-builds/apkdiff/apkdiff.py index f3f9ed8045..077ceefd95 100755 --- a/reproducible-builds/apkdiff/apkdiff.py +++ b/reproducible-builds/apkdiff/apkdiff.py @@ -56,7 +56,19 @@ def compare(apk1, apk2) -> bool: entry_names = compare_entry_names(zip1, zip2) entry_contents = compare_entry_contents(zip1, zip2) - resources = compare_resources_arsc(apk1, apk2) + + # Some splits (e.g. ABI config splits) contain no resource table. Compare when both APKs have one, treat both + # missing as a match, and fail if only one of them has it. + has_arsc_1 = "resources.arsc" in zip1.namelist() + has_arsc_2 = "resources.arsc" in zip2.namelist() + + if has_arsc_1 and has_arsc_2: + resources = compare_resources_arsc(apk1, apk2) + elif has_arsc_1 != has_arsc_2: + print("resources.arsc is present in only one of the APKs!") + resources = False + else: + resources = True return entry_names and entry_contents and resources @@ -200,11 +212,11 @@ def compare_resources_arsc(apk1: str, apk2: str) -> bool: else: print("resources.arsc files differ!") diff = difflib.unified_diff( - resources1, - resources2, - fromfile=apk1, - tofile=apk2, - lineterm='' + resources1, + resources2, + fromfile=apk1, + tofile=apk2, + lineterm="", ) for line in diff: print(line)