beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.59k stars 364 forks source link

Better accomodate installing APK on physical device when existing app cannot be replaced #1362

Open rmartin16 opened 1 year ago

rmartin16 commented 1 year ago

Describe the bug

The current APK install process can error if an existing version of the app cannot be replaced. For me, this happened because the existing app on the device was installed from a different computer.

[helloworld] Starting app on SM G960U (5759363737573398) (device ID 5759363737573398)

[helloworld] Installing app...

>>> Running Command:
>>>     /home/russell/.cache/briefcase/tools/android_sdk/platform-tools/adb -s 5759363737573398 shell am force-stop com.example.helloworld
>>> Working Directory:
>>>     /home/russell/tmp/beeware/helloworld
>>> Return code: 0
Stopping old versions of the app... done

>>> Running Command:
>>>     /home/russell/.cache/briefcase/tools/android_sdk/platform-tools/adb -s 5759363737573398 install -r /home/russell/tmp/beeware/helloworld/build/helloworld/android/gradle/app/build/outputs/apk/debug/app-debug.apk
>>> Working Directory:
>>>     /home/russell/tmp/beeware/helloworld
>>> Command Output:
>>>     adb: failed to install /home/russell/tmp/beeware/helloworld/build/helloworld/android/gradle/app/build/outputs/apk/debug/app-debug.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.example.helloworld signatures do not match previously installed version; ignoring!]
>>>     Performing Streamed Install
>>> Return code: 1
Installing new app version...

Unable to install APK /home/russell/tmp/beeware/helloworld/build/helloworld/android/gradle/app/build/outputs/apk/debug/app-debug.apk on 5759363737573398

Steps to reproduce

  1. Install an APK on a physical device
  2. Attempt to install APK from a different machine or using a different identity

Expected behavior

Fallback to an uninstall and install workflow or at least provide better information to the user about what's wrong.

A simple remedy is ~/.cache/briefcase/tools/android_sdk/platform-tools/adb uninstall "com.example.helloworld"

Screenshots

No response

Environment

Logs

briefcase.2023_07_14-17_02_12.run.log

Additional context

No response

mhsmith commented 1 year ago

Fallback to an uninstall and install workflow or at least provide better information to the user about what's wrong.

I think the message is already clear enough, but falling back to a separate uninstall and install would still be useful. However, I think we should ask for confirmation first, as Android Studio does, with a warning that uninstalling the existing app will wipe out all of its data.

A similar situation could happen with the INSTALL_FAILED_VERSION_DOWNGRADE error.

mhsmith commented 1 year ago

I think the message is already clear enough

Actually, as we've just found out from a user on Discord, the message is not displayed in non-verbose mode. All Briefcase displays in the console is:

Installing new app version...

Unable to install APK

[General discusssion moved to:]

freakboy3742 commented 1 year ago

[Moved to #1907]

freakboy3742 commented 11 months ago

I think the message is already clear enough

Yes, the subprocess output hints at the cause; but it also says that the problem was "ignored" - which... it clearly isn't (at least, not in a way that makes any sense to a Briefcase user).

I'd suggest that we should inspect the output for the INSTALL_FAILED_* marker, and convert that into a more helpful error message if it is detected. If we're able to get a comprehensive list of those failure markers, that would be great; but if not, starting with the 2 we know about an expanding the list as they're reported would also be a significant improvement.