shorebird icon indicating copy to clipboard operation
shorebird copied to clipboard

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

Open Jonny1987 opened this issue 1 year ago • 10 comments

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 avatar May 15 '24 23:05 Jonny1987

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

Jonny1987 avatar May 16 '24 12:05 Jonny1987

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.

eseidel avatar May 16 '24 15:05 eseidel

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

Jonny1987 avatar May 16 '24 16:05 Jonny1987

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 avatar May 16 '24 16:05 eseidel

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

eseidel avatar Jun 12 '24 17:06 eseidel

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

WangSire avatar Aug 23 '24 08:08 WangSire

Hello, I am facing the same issue Any plans to resolve this issue?

json-kim avatar Nov 18 '24 03:11 json-kim

I think the easy fix would be for us to add the ability to specify a key store when using shorebird preview.

eseidel avatar Nov 18 '24 17:11 eseidel

Basically we could just pass certain arguments (like --ks) through to build-apks: https://developer.android.com/tools/bundletool

eseidel avatar Nov 18 '24 17:11 eseidel

Felix has implemented this in 1.5.5.

https://github.com/shorebirdtech/shorebird/commit/ce2b9ebc6132174274ca615c8966b09b89968f2f

I'm not sure if that fully solves the issue however, since it's still confusing to users.

eseidel avatar Jan 15 '25 19:01 eseidel