build(android): build and sign a release, without the password touching anything
build-apk.ps1 -Release builds the Release configuration and signs with the user's keystore. Not through Delphi's Provisioning page, for three reasons: the .dproj is versioned, paclient --apksign puts the password ON THE COMMAND LINE where any process on the machine reads it, and tooling belongs in the repository rather than hidden in an IDE setting. apksigner called directly accepts --ks-pass env:. The password is asked for with Read-Host -AsSecureString - nothing echoed, nothing left in console history - handed over through an environment variable, and removed in a finally even when the script fails. It prints the certificate it signed with. A release signed by accident with the debug key installs and runs: nothing tells it apart in use, and one finds out only when the first update is refused. It does not install the release. Android refuses a different signature on an existing package, and uninstalling would wipe the local cache and the device's settings - a deliberate act, not a script's side effect. Keystores are gitignored. The debug path is unchanged and still builds.
This commit is contained in:
@@ -8,6 +8,21 @@
|
||||
# remet ce qu'il a efface et on refait aapt / zipalign / signature.
|
||||
#
|
||||
# A lancer depuis la racine du depot, apres un Deploy reussi.
|
||||
#
|
||||
# -Config Release empaquette la sortie Release au lieu de Debug
|
||||
# -Keystore <chemin> -Alias signe avec CETTE cle au lieu de celle de debogage
|
||||
#
|
||||
# LE MOT DE PASSE NE PASSE PAS PAR LA LIGNE DE COMMANDE. paclient --apksign
|
||||
# l'y met en clair, ou n'importe quel processus de la machine peut le lire.
|
||||
# apksigner sait lire une variable d'environnement ; on l'appelle donc en
|
||||
# direct pour une vraie cle, et on ne garde paclient que pour la cle de
|
||||
# debogage, dont le mot de passe est public et vaut "android".
|
||||
|
||||
param(
|
||||
[ValidateSet('Debug', 'Release')] [string]$Config = 'Debug',
|
||||
[string]$Keystore,
|
||||
[string]$Alias
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
@@ -15,7 +30,7 @@ $sdk = 'C:\Users\Public\Documents\Embarcadero\Studio\23.0\CatalogRepository\And
|
||||
$bds = 'C:\Program Files (x86)\Embarcadero\Studio\23.0'
|
||||
$jdk = 'C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot'
|
||||
$pac = "$bds\bin\paclient.exe"
|
||||
$p = '.\Android64\Debug\pmserverApk'
|
||||
$p = ".\Android64\$Config\pmserverApk"
|
||||
|
||||
# 1. Nos icones par-dessus celles de Delphi :
|
||||
# les proprietes Android_LauncherIcon* et Android_AdaptiveIcon* du .dproj
|
||||
@@ -46,8 +61,27 @@ Remove-Item "$p\bin\pmserverApk.apk" -Force -ErrorAction SilentlyContinue
|
||||
& $pac -u8 --zipalign="$sdk\build-tools\33.0.2\ZipAlign.exe,$p\bin\pmserverApk-unaligned.apk,$p\bin\pmserverApk.apk,4"
|
||||
if ($LASTEXITCODE -ne 0) { throw "zipalign a echoue" }
|
||||
|
||||
& $pac -u8 --apksign="$jdk\bin\java.exe,$sdk\build-tools\33.0.2\lib\apksigner.jar,$p\bin\pmserverApk.apk,androiddebugkey,$env:APPDATA\Embarcadero\BDS\23.0\debug.keystore,android,android"
|
||||
if ($LASTEXITCODE -ne 0) { throw "signature echouee" }
|
||||
if ($Keystore) {
|
||||
# LA CLE DE L'UTILISATEUR. Le mot de passe arrive par PM_KS_PASS, pose par
|
||||
# l'appelant juste avant et retire juste apres : il ne figure ni dans le
|
||||
# depot, ni dans le .dproj, ni dans une ligne de commande.
|
||||
if (-not $env:PM_KS_PASS) { throw 'PM_KS_PASS absent - mot de passe du magasin' }
|
||||
& "$jdk\bin\java.exe" -jar "$sdk\build-tools\33.0.2\lib\apksigner.jar" sign `
|
||||
--ks "$Keystore" --ks-key-alias "$Alias" `
|
||||
--ks-pass env:PM_KS_PASS --key-pass env:PM_KS_PASS `
|
||||
"$p\bin\pmserverApk.apk"
|
||||
if ($LASTEXITCODE -ne 0) { throw "signature echouee" }
|
||||
# DIRE AVEC QUOI ON A SIGNE. Une release signee par megarde avec la cle de
|
||||
# debogage s'installe et fonctionne : rien ne la distingue a l'usage, et on
|
||||
# ne s'en apercoit qu'au refus de la premiere mise a jour.
|
||||
& "$jdk\bin\java.exe" -jar "$sdk\build-tools\33.0.2\lib\apksigner.jar" `
|
||||
verify --print-certs "$p\bin\pmserverApk.apk" |
|
||||
Select-String -Pattern 'Signer #1 certificate DN|SHA-256 digest' |
|
||||
ForEach-Object { $_.Line.Trim() }
|
||||
} else {
|
||||
& $pac -u8 --apksign="$jdk\bin\java.exe,$sdk\build-tools\33.0.2\lib\apksigner.jar,$p\bin\pmserverApk.apk,androiddebugkey,$env:APPDATA\Embarcadero\BDS\23.0\debug.keystore,android,android"
|
||||
if ($LASTEXITCODE -ne 0) { throw "signature echouee" }
|
||||
}
|
||||
|
||||
$apk = Get-Item "$p\bin\pmserverApk.apk"
|
||||
"APK {0:N1} Mo" -f ($apk.Length / 1MB)
|
||||
|
||||
Reference in New Issue
Block a user