Repository navigation
Judge tool success by exit code and warn on outdated apktool - #25
Merged
Merged
Conversation
Every external tool (apktool, adb, zipalign, apksigner, aapt2) was judged successful only when its stderr was empty, or by matching a stdout string. adb prints progress to stderr, apktool prints warnings, and apksigner on JDK 25 prints native-access WARNINGs, all on successful runs, so these checks produced false failures (e.g. `build` ending in "Failed" after a correctly signed APK). `_run_subprocess` now also returns the exit code and every caller decides by it; stderr on a successful run is shown as a yellow warning, and an error message falls back to stdout or the exit code when stderr is empty. `decode`, `build`, `debuggable`, `network` and `all` now print a warning when apktool is older than 2.9.0 (APKTOOL_MIN_VERSION) or its version can't be determined. The build itself is unaffected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #24. The root cause shared by the apktool 3 breakage, the earlier adb stdout/stderr fix (#21) and the
sign()failure on JDK 25 is that apkutil never looked at the exit code of the tools it wraps: success was "stderr is empty" (adb/apksigner/zipalign/aapt2) or "stdout contains a magic string" (apktool build). Both are unreliable, since adb prints progress to stderr, apktool printsW:warnings, and apksigner on JDK 25 prints native-accessWARNING:lines, all on successful runs.1. Exit code decides
_run_subprocess()now returns(stdout, stderr, returncode).decode,build,align,sign,get_packagename,get_screenshot,_get_package_name,_get_apk_paths,_pull_apk_files) raises/returns False only whenreturncode != 0. TheI: Built apkstring match from Support apktool 2.12+/3.x builds while keeping aapt2 on older apktool #24 is gone.<tool> exited with code N(e.g.pm pathon an unknown package prints nothing)._pull_apk_filesand theadb pullinget_screenshotpreviously ignored failures entirely; they now raise.decode-f switchworkaround, the~/apkutil.jsonschema, subcommand behavior otherwise.Net effect for users:
apkutil build/all/...on JDK 25 now finishes withOutput: ...instead ofFailedafter a correctly signed APK.2. Outdated apktool warning
util.warn_if_apktool_outdated()runs once at the start ofdecode,build,debuggable,networkandall. It prints a yellow warning (never fails) when apktool is older thanAPKTOOL_MIN_VERSION = (2, 9, 0), or when the version can't be parsed. Missing apktool stays silent here becausedecode()/build()already report it. README lists 2.9.0 as the recommended minimum.Why 2.9.0: it is the first release where aapt2 is the default, and older releases can't even decode APKs built by recent aapt2 (2.8.1 failed on the test fixture). The
--use-aapt2runtime detection from #24 still keeps < 2.12 on aapt2, so older versions keep working; they just get told.Version
0.1.11->0.1.12(user-visible change in build/sign outcome).Tests
31 tests (was 19), Python 3.8.5 and 3.14.7, no apktool/SDK/keystore needed. New coverage: exit-code-driven success/failure for build/decode/align/sign/get_packagename, message fallback to stdout and to the exit code,
sign()succeeding with JVM warnings on stderr, and the version warning (recent = silent, 2.8.1 = warns, unparseable = warns, missing = silent).Manual verification (apktool 3.0.3 unless noted, build-tools 36.0.0, OpenJDK 25, emulator attached)
build/all:Signed+ yellow JDK warnings +Output: ...(wasFailed)decodeonto an existing dir:Destination directory (sample) already exists. ...+Failed(error path intact)buildwith apktool 2.8.1: printsapktool 2.8.1 is outdated. Please upgrade to apktool 2.9.0 or later., then builds with--use-aapt2and itsW: Could not find sourcesshows as a warning instead of failingbuildwith apktool 2.9.3: no warningapktool not found.unchangedinfoon a valid / nonexistent APK: package name / aapt2 error +Failedscreenshot: pulled and removed from the device,Output: screenshot-....pngcom.android.settings: list, path and pull succeed; unknown package now raisesadb exited with code 1instead of an empty message🤖 Generated with Claude Code