Skip to content

fix(install): make InstallError.code the reason code alone, and quote the apk path with '!' - #598

Merged
koral-- merged 2 commits into
masterfrom
fix/install-error-code
Nov 23, 2026
Merged

koral-- merged 2 commits into
masterfrom
fix/install-error-code

Conversation

@koral--

@koral-- koral-- commented Nov 23, 2026

Copy link
Copy Markdown
Member

Two small fixes in install / installRemote, one commit each.

1. InstallError.code is the reason code alone

Modern Android prints a failed install as Failure [INSTALL_FAILED_X: description]. The error's code was the whole bracket text, so err.code === 'INSTALL_FAILED_UPDATE_INCOMPATIBLE' never matched; callers had to strip the description themselves.

  • code is now the part before the first : (INSTALL_FAILED_UPDATE_INCOMPATIBLE).
  • The error's message still holds the full text, description included.
  • The old form Failure [INSTALL_FAILED_X] (no colon) gives the same code as before.
  • Tests cover both formats; README updated.

Behavior change: code that matched the old long string now sees only the short code. Exact and startsWith checks on the short code both work.

2. Single-quote the apk path (! escape)

installRemote() quoted the apk path with _escapeCompat(), which turns ! into \!. The device shell keeps the backslash, so pm was given bang\!A.apk. It now uses _escape(), like the other arguments ('...').

Tested

  • npm run lint, npm test (398 passing).
  • Android 16 emulator (own instance, adbkit script only):
    • Installed an apk signed with key A, then the same package signed with key B: err.code === 'INSTALL_FAILED_UPDATE_INCOMPATIBLE', and err.message is ... could not be installed [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package ... signatures do not match newer version; ignoring!].
    • installRemote('/data/local/tmp/bang!A.apk'): before, INSTALL_EXCEPTION ... Can't open file: /data/local/tmp/bang\!A.apk; after, it installs.

🤖 Generated with Claude Code

koral-- and others added 2 commits November 23, 2026 18:13
Newer Android prints a failed install as
Failure [INSTALL_FAILED_X: description], and the error's code was the
whole bracket text, so a check such as
code === 'INSTALL_FAILED_UPDATE_INCOMPATIBLE' never matched. The code is
now the part before the first colon. The error's message still holds the
full text, description included. The old Failure [INSTALL_FAILED_X] form
gives the same code as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Karol Wrótniak <[email protected]>
installRemote() quoted the apk path with _escapeCompat(), which turns
'!' into '\!'. The device's shell keeps the backslash, so pm looked for
bang\!A.apk instead of bang!A.apk and failed with "Can't open file".
Use _escape(), as the other arguments already do. Checked on an Android
16 emulator: before, installRemote('/data/local/tmp/bang!A.apk') rejected
with INSTALL_EXCEPTION; after, it installs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Karol Wrótniak <[email protected]>
@koral--
koral-- merged commit 4a72a35 into master Nov 23, 2026
6 checks passed
@koral--
koral-- deleted the fix/install-error-code branch November 23, 2026 18:08
koral-- added a commit to mdub1na/stf that referenced this pull request Nov 24, 2026
…IBLE

Installing an app signed with another key than the installed one is
supposed to uninstall the app and install again. The retry only checked
INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, the code of old Android
versions. Modern Android reports INSTALL_FAILED_UPDATE_INCOMPATIBLE, so
the install failed with that message and the retry never ran. Add the
code to the retry. The uninstall wipes the app's data, as it did before.

This needs an adbkit release that sets InstallError.code to the reason
code alone (DeviceFarmer/adbkit#598). Until the dependency is bumped,
modern Android still reports the code with its description and the retry
does not trigger.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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