shorebirdtech / shorebird

Code Push for Flutter and other tools for Flutter businesses.
https://shorebird.dev
Other
2.32k stars 140 forks source link

`shorebird preview` calls `bundle-tool build-apks` which might sign with the wrong keystore #2113

Open Jonny1987 opened 5 months ago

Jonny1987 commented 5 months ago

App ID: 71b9cd57-235e-40ab-8d25-1861aa29aadf

Description

I am getting the following error after creating an android release and then running shorebird preview. Changed my keystore for the release version after setting up shorebird, but looking at the logs (The APKs will be signed with the debug keystore found at '/home/john/.android/debug.keystore'.), it is still trying to use the old keystore (debug.keystore).

I've tried reinstalling shorebird, cleaning cache, re-initialising shorebird and cleaning flutter cache.

Error:

Exception: Failed to install apks: The APKs have been extracted in the directory: /tmp/2698427712535263786
[BT:1.15.6] Error: Installation of the app failed.
com.android.tools.build.bundletool.model.exceptions.CommandExecutionException: Installation of the app failed.
    at com.android.tools.build.bundletool.model.exceptions.InternalExceptionBuilder.build(InternalExceptionBuilder.java:57)
    at com.android.tools.build.bundletool.device.DdmlibDevice.installApks(DdmlibDevice.java:196)
    at com.android.tools.build.bundletool.commands.InstallApksCommand.lambda$execute$2(InstallApksCommand.java:236)
    at com.android.tools.build.bundletool.device.AdbRunner.run(AdbRunner.java:81)
    at com.android.tools.build.bundletool.device.AdbRunner.run(AdbRunner.java:43)
    at com.android.tools.build.bundletool.commands.InstallApksCommand.execute(InstallApksCommand.java:236)
    at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:117)
    at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:55)
Caused by: com.android.ddmlib.InstallException: Failed to commit install session 2145140906 with command cmd package install-commit 2145140906. Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.getworkwith.workwith signatures do not match newer version; ignoring!

Steps To Reproduce

  1. Install and init shorebird
  2. change release keystore in build.gradle
  3. shorebird release android
  4. shorebird preview

Expected Behavior

Shorebird should use the new keystore

Jonny1987 commented 5 months ago

I realise this error is because shorebird preview simply uses the default debug keystore and I was expecting it to use the release keystore. Also, my app was not working even when uninstalling the previous version first because I had set the debug keystore in build.gradle to a different one and was again expecting that shorebird would use that. Reverting back to the default keystore with default alias and password makes everything work

eseidel commented 5 months ago

shorebird preview just downloads and installs the saved off .aab from a previous shorebird release. It doesn't do any building or use any keystores (to my knowledge).

I would expect shorebird release to use flutter build --release which I would expect to use the release keystore in Gradle.

There might still be something for us to fix here? I'm not yet sure.

Jonny1987 commented 5 months ago

So I checked the certificate of the aab file and it WAS the correct (release) one.

But the preview command was still using debug.keystore according to it's logs.

It looks like the preview command builds the apks using bundletool build-apks command. Since the keystore is not being specified it uses the default one (https://developer.android.com/tools/bundletool). Which means if someone has changed their default one (although not sure why they would...I realised I didn't need to and have changed mine back to the default) then it won't work. (Also, should it be using the release keystore one here? Maybe it doesn't matter...I'm new to mobile development)

I think this issue was just because I changed my default debug keystore in build.gradle for a reason which wasn't actually a good reason, and probably nobody ever needs to change it

eseidel commented 5 months ago

Wow, you're right. I didn't realize that bundletool could end up changing the signing! https://github.com/shorebirdtech/shorebird/blob/9a6c162fe19623305c7f551e27b3cd1df443e8f2/packages/shorebird_cli/lib/src/commands/preview_command.dart#L274

eseidel commented 4 months ago

I'm not sure how we tell bundle-tool to use whatever keystore is set for the "release" flavor of the build in gradle?

WangSire commented 2 months ago

Hello, I am facing the same issue as the landlord. Could you please advise me on how to resolve it?