Skip to content

feat: Add code signing for Android release artefacts#2724

Open
JohananOppongAmoateng wants to merge 11 commits intobeeware:mainfrom
JohananOppongAmoateng:publishing-android
Open

feat: Add code signing for Android release artefacts#2724
JohananOppongAmoateng wants to merge 11 commits intobeeware:mainfrom
JohananOppongAmoateng:publishing-android

Conversation

@JohananOppongAmoateng
Copy link
Copy Markdown
Contributor

Add code signing for Android release artefacts Closes #1268

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I've given a partial review; the general shape of things looks good, but there's some reorganisation that will be required, and I'm not 100% certain about some of the details in the implementation (specifically, if the -P arguments you're referring to are standard features, or something we'll need to accomodate).

I haven't done a full review of the test cases yet, mostly because they'll see a bunch of changes from the reorganisation.

f"-Pandroid.injected.signing.store.file={signing_config.keystore_path!s}",
f"-Pandroid.injected.signing.store.password={signing_config.store_password}",
f"-Pandroid.injected.signing.key.alias={signing_config.alias}",
f"-Pandroid.injected.signing.key.password={signing_config.key_password}",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these standard configuration points, or do we need to modify the Android gradle template to support these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These work with the android gradle plugin so we dont need to modify the gradle template

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although these properties aren't documented, it looks like they've always been the way in which Android Studio passes signing settings to Gradle when building from the GUI, so they should be safe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, for future reference, the code should include the above explanation and link.

@JohananOppongAmoateng
Copy link
Copy Markdown
Contributor Author

@freakboy3742 i will address all your concerns later bogged down with work now

@mhsmith mhsmith requested review from mhsmith and removed request for freakboy3742 March 17, 2026 14:46

build_type, build_artefact_path = {
"aab": ("bundleRelease", "bundle/release/app-release.aab"),
"apk": ("assembleRelease", "apk/release/app-release-unsigned.apk"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the signing options are passed, this filename changes to app-release.apk – see #2189 (comment).

### run
### package { #android-package }

#### `--keystore-alias <alias>`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, this and its references elsewhere should be called key-alias.

Comment on lines +139 to +141
#### `-i <path>` / `--identity <path>`

The path to a `.jks` keystore file to use for signing. If not provided, Briefcase will search for existing keystores in the project folder (`.android/`), and in the `.android` folder in the user's home directory, and offer to create a new one if none are found.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're trying to be consistent with macOS and Windows, but Android doesn't really have an equivalent to those platforms' --identity options, so reusing the same name is confusing. Suggest renaming it to --keystore. @freakboy3742: what do you think?

Either way, a note about Android should be added to the --identity section of package.md.

Comment on lines +390 to +391
* The project's `.android/` subfolder
* The `.android/` folder in the user's home directory
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freakboy3742: Was this based on some existing convention? My impression is that the .android/ folder in the user's home directory mostly contains ephemeral files automatically managed by the Android build tools, so encouraging the user to put a permanent key in there seems like a bad idea. Encouraging them to put it in the project directory is also risky, as this will likely lead them to commit it to source control.

So I suggest we remove all assumptions about the keystore location, and require the user always to specify it explicitly, including when creating it.

Comment on lines +1427 to +1430
keystore_path: Path
alias: str
store_password: str
key_password: str
Copy link
Copy Markdown
Member

@mhsmith mhsmith Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order and names of these fields should match the documentation of the command-line arguments (see comments in gradle.md).

keystore_alias = self.tools.console.text_question(
description="Key alias",
intro="Enter an alias for the signing key.",
default=app.app_name,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better default would be "mykey", since that's the default used by keytool itself.

default=app.app_name,
)

if store_password is None:
Copy link
Copy Markdown
Member

@mhsmith mhsmith Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question order should match the documentation of the command-line arguments (see comments in gradle.md).

Comment on lines +1515 to +1518
"-keyalg",
"RSA",
"-keysize",
"2048",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


extra_gradle = getattr(app, "build_gradle_extra_content", "") or ""
if "signingConfig" in extra_gradle:
if identity is not None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error should appear when passing any keystore options, not just --identity.

""")
adhoc_sign = True

if app.packaging_format != "debug-apk" and not adhoc_sign:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to upgrade in-place between debug and release builds, both apps must be signed with the same key. So It should be possible to sign the app even in debug-apk mode, even though this is not the default.

adhoc_sign = True

if app.packaging_format != "debug-apk" and not adhoc_sign:
with self.console.wait_bar("Selecting signing credentials..."):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either select_keystore will show some interactive questions, or it'll return immediately. Either way, I don't think a wait_bar is necessary.

{keystore_path}

Keep this file secure and backed up. If you lose it, you will not be able to
publish updates to this app on the Play Store.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is enforced by Android itself, not just the Play Store.

Suggested change
publish updates to this app on the Play Store.
publish updates to this app.

@mhsmith
Copy link
Copy Markdown
Member

mhsmith commented Mar 30, 2026

Thanks, I'll look at this as soon as I can.

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.

Add code signing for Android release artefacts

3 participants