feat: Add code signing for Android release artefacts#2724
feat: Add code signing for Android release artefacts#2724JohananOppongAmoateng wants to merge 11 commits intobeeware:mainfrom
Conversation
freakboy3742
left a comment
There was a problem hiding this comment.
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}", |
There was a problem hiding this comment.
Are these standard configuration points, or do we need to modify the Android gradle template to support these?
There was a problem hiding this comment.
These work with the android gradle plugin so we dont need to modify the gradle template
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
However, for future reference, the code should include the above explanation and link.
|
@freakboy3742 i will address all your concerns later bogged down with work now |
|
|
||
| build_type, build_artefact_path = { | ||
| "aab": ("bundleRelease", "bundle/release/app-release.aab"), | ||
| "apk": ("assembleRelease", "apk/release/app-release-unsigned.apk"), |
There was a problem hiding this comment.
When the signing options are passed, this filename changes to app-release.apk – see #2189 (comment).
| ### run | ||
| ### package { #android-package } | ||
|
|
||
| #### `--keystore-alias <alias>` |
There was a problem hiding this comment.
For consistency, this and its references elsewhere should be called key-alias.
| #### `-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. |
There was a problem hiding this comment.
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.
| * The project's `.android/` subfolder | ||
| * The `.android/` folder in the user's home directory |
There was a problem hiding this comment.
@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.
| keystore_path: Path | ||
| alias: str | ||
| store_password: str | ||
| key_password: str |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
A better default would be "mykey", since that's the default used by keytool itself.
| default=app.app_name, | ||
| ) | ||
|
|
||
| if store_password is None: |
There was a problem hiding this comment.
The question order should match the documentation of the command-line arguments (see comments in gradle.md).
| "-keyalg", | ||
| "RSA", | ||
| "-keysize", | ||
| "2048", |
There was a problem hiding this comment.
This should link to https://developer.android.com/build/building-cmdline#sign_cmdline.
|
|
||
| extra_gradle = getattr(app, "build_gradle_extra_content", "") or "" | ||
| if "signingConfig" in extra_gradle: | ||
| if identity is not None: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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..."): |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
This is enforced by Android itself, not just the Play Store.
| publish updates to this app on the Play Store. | |
| publish updates to this app. |
|
Thanks, I'll look at this as soon as I can. |
Add code signing for Android release artefacts Closes #1268
PR Checklist: