install.ps1 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <#
  2. publish-android.ps1
  3. Builds and signs an Android App Bundle (.aab) for a net9.0-android Avalonia app.
  4. Usage examples:
  5. .\publish-android.ps1 -ProjectPath .\YourApp.Android.csproj -AppId com.example.weave -VersionCode 12 -VersionName 1.1.0 `
  6. -KeystorePath "$env:USERPROFILE\keystores\upload.jks" -KeyAlias upload
  7. #>
  8. param(
  9. [string]$ProjectPath = ".\PRS.Avalonia.Android.csproj",
  10. [string]$Configuration = "Release",
  11. [string]$Framework = "net9.0-android",
  12. [string]$AppId = "com.frogsoftware.avalonia",
  13. [int]$VersionCode = 1,
  14. [string]$VersionName = "1.0.0",
  15. [string]$AndroidSDK = "C:\Users\frank.vandenbos\AppData\Local\Android\sdk",
  16. # Keystore
  17. [string]$KeystorePath = ".\upload-keystore.jks",
  18. [string]$KeyAlias = "upload",
  19. # Optional. If omitted, you will be prompted without echo.
  20. [string]$KeystorePass = "Pr5S0ftw4r3!",
  21. [string]$KeyPass = "Pr5S0ftw4r3!"
  22. )
  23. $ErrorActionPreference = "Stop"
  24. Write-Host "=== Android AAB publish for $ProjectPath ===`n"
  25. # 1. Tools check
  26. function Test-Cmd($cmd) {
  27. $null -ne (Get-Command $cmd -ErrorAction SilentlyContinue)
  28. }
  29. if (-not (Test-Cmd "dotnet")) {
  30. throw "dotnet not found on PATH. Install .NET 9 SDK."
  31. }
  32. # keytool and jarsigner come with a JDK
  33. $HasKeytool = Test-Cmd "keytool"
  34. $HasJarsigner = Test-Cmd "jarsigner"
  35. if (-not $HasKeytool) {
  36. Write-Warning "keytool not found on PATH. Install a JDK and reopen your shell. Will continue if keystore already exists."
  37. }
  38. # 2. Workload check
  39. #$workloads = & dotnet workload list
  40. #if ($workloads -notmatch '^\s*android\s') {
  41. # Write-Host "Installing .NET Android workload..."
  42. # & dotnet workload install android
  43. #}
  44. # 3. Project and directories
  45. if (-not (Test-Path $ProjectPath)) {
  46. throw "Project not found at $ProjectPath"
  47. }
  48. $ProjectDir = Split-Path -Parent (Resolve-Path $ProjectPath)
  49. # 4. Keystore presence or creation
  50. #if (-not (Test-Path $KeystorePath)) {
  51. # if (-not $HasKeytool) {
  52. # throw "Keystore missing and keytool not available to create one. Install a JDK or create the keystore manually."
  53. # }
  54. # Write-Host "Keystore not found. Creating a new upload keystore at $KeystorePath"
  55. # New-Item -ItemType Directory -Force -Path (Split-Path -Parent $KeystorePath) | Out-Null
  56. #
  57. # if (-not $KeystorePass) {
  58. # $KeystorePass = Read-Host -AsSecureString "Enter NEW keystore password"
  59. # $KeystorePassPlain = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($KeystorePass))
  60. # } else {
  61. # $KeystorePassPlain = $KeystorePass
  62. # }
  63. #
  64. # if (-not $KeyPass) { $KeyPass = $KeystorePassPlain }
  65. # $KeyPassPlain = $KeyPass
  66. #
  67. # & keytool -genkeypair -v `
  68. # -keystore "$KeystorePath" `
  69. # -storepass "$KeystorePassPlain" `
  70. # -alias "$KeyAlias" `
  71. # -keypass "$KeyPassPlain" `
  72. # -keyalg RSA -keysize 2048 -validity 36500 `
  73. # -dname "CN=Upload, OU=Dev, O=YourOrg, L=City, S=State, C=AU"
  74. # Write-Host "Keystore created."
  75. #} else {
  76. if (-not $KeystorePass) {
  77. $sec = Read-Host -AsSecureString "Enter keystore password"
  78. $KeystorePass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec))
  79. }
  80. if (-not $KeyPass) {
  81. $sec2 = Read-Host -AsSecureString "Enter key password (press Enter to reuse keystore password)"
  82. if ($sec2.Length -gt 0) {
  83. $KeyPass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec2))
  84. } else {
  85. $KeyPass = $KeystorePass
  86. }
  87. }
  88. #}
  89. # 5. Restore and Publish to AAB
  90. #Write-Host "`nRestoring..."
  91. #& dotnet restore "$ProjectPath"
  92. Write-Host "Publishing signed .aab..."
  93. & dotnet publish "$ProjectPath" `
  94. -c "$Configuration" `
  95. -f "$Framework" `
  96. /p:AndroidKeyStore=true `
  97. /p:AndroidSdkDirectory="$AndroidSDK" `
  98. /p:AndroidSigningKeyStore="$KeystorePath" `
  99. /p:AndroidSigningStorePass="$KeystorePass" `
  100. /p:AndroidSigningKeyAlias="$KeyAlias" `
  101. /p:AndroidSigningKeyPass="$KeyPass" `
  102. /p:AndroidPackageFormat=aab `
  103. /p:ApplicationId="$AppId" `
  104. /p:VersionCode="$VersionCode" `
  105. /p:VersionName="$VersionName"
  106. # 6. Find the newest AAB under the expected bin folder
  107. $binRoot = Join-Path $ProjectDir "bin\$Configuration\$Framework"
  108. $aab = Get-ChildItem -Path $binRoot -Recurs