如何使用 azure pipeline 生成 .AAB 文件并签署 Android 应用程序包

问题描述 投票:0回答:3

我想使用 Azure 管道生成 Android 应用程序包 (.aab) 文件,但在生成 Android 应用程序包文件时遇到问题。

我使用下面的 Gradle 任务来生成并签署 .aab 文件。但是,它生成 .APK 文件。我想生成 .aab 文件。

- task: Gradle@2
  inputs:
    gradleWrapperFile: 'gradlew'
    tasks: 'buildRelease'
    publishJUnitResults: false
    javaHomeOption: 'JDKVersion'
    sonarQubeRunAnalysis: false
    spotBugsAnalysis: false

这是脚本,我使用 jarsigner 来签署 .aab 文件:

- task: CmdLine@2
  displayName: 'Signing and aligning AAB file(s) app\build\outputs\bundle\release\app-release.aab'
  inputs:
    script: 'jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore $(KeyStoreFile.secureFilePath) -storepass $(StorePassword) -keypass $(KeyPassword) $(system.defaultworkingdirectory)/app/build/outputs/bundle/release/app-release.aab $(KeyStoreAlias)'
android azure azure-devops azure-pipelines
3个回答
14
投票

在 Gradle 任务中: 我需要将

tasks
值 '
buildRelease
' 更改为 '
:app:bundleRelease
' 以生成 .aab 文件。

这是我用来生成和签署 .aab 文件的 .yaml 文件:

trigger:
- master

pool:
  vmImage: ubuntu-latest

steps:
- task: DownloadSecureFile@1
  name: KeyStoreFile
  inputs:
    secureFile: 'AndroidApp.jks'

- task: Gradle@2
  inputs:
    gradleWrapperFile: 'gradlew'
    tasks: ':app:bundleRelease'
    publishJUnitResults: false
    javaHomeOption: 'JDKVersion'
    sonarQubeRunAnalysis: false
    spotBugsAnalysis: false


- task: CmdLine@2
  displayName: 'Signing and aligning AAB file(s) app\build\outputs\bundle\release\app-release.aab'
  inputs:
    script: 'jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore $(KeyStoreFile.secureFilePath) -storepass $(StorePassword) -keypass $(KeyPassword) $(system.defaultworkingdirectory)/app/build/outputs/bundle/release/app-release.aab $(KeyStoreAlias)'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(system.defaultworkingdirectory)/app/build/outputs/bundle/release/'
    Contents: '**'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

我在签名任务中创建并使用了以下变量:

KeyStoreFile.secureFilePath
StorePassword
KeyPassword
KeyStoreAlias

2
投票

我个人在应用程序 gradle 文件中添加了签名过程(此过程仅针对发布版本执行)。这样,在所有构建(在您的计算机或天蓝色管道中)之后,生成的 apk/aab 将被签名。 我的项目中有一个像这样的 keystore.properties :

storePassword=****
keyPassword=****
keyAlias=****
storeFile=/** jks path **/

应用程序 build.gradle 文件包含使用我的属性文件发布构建变体的签名过程:

apply plugin: 'com.android.application'

// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

def versionPropertiesFile = rootProject.file("version.properties")

// Initialize a new Properties() object called versionProperties.
def versionProperties = new Properties()

// Load your version.properties file into the versionProperties object.
versionProperties.load(new FileInputStream(versionPropertiesFile))

....
android {
signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['storePassword']
    }
}
compileSdkVersion 30
defaultConfig {
    //.....
}
buildTypes {
    release {
        //+ specify the signing config
        signingConfig signingConfigs.release
    }
.....

这里缺少一件事!如何更改 keystore.properties 文件中的 jks 路径(天蓝色管道不知道)? 这是通过 azure pipeline 完成的,该任务在构建任务之前使用 azure 变量 作为密码和别名以及 azure pipeline 安全文件 用于 jks 文件生成此文件。

steps:
  #get the keyStore file encoded
  - task: DownloadSecureFile@1
    name: yourNameHere
    displayName: 'Get KeyStore file'
    inputs:
      secureFile: 'yourKeyStoreBase64Encoded.txt'
    # decode the keystore base-64 encoded string of our jks certificate into storeFile
  - script: |
      cat $(yourNameHere.secureFilePath) | base64 --decode > $(KeyStore.Name)
    displayName: Create jks certificate
    # rewrite keystore.properties
  - script: |
      printf 'storePassword=%s\nkeyPassword=%s\nkeyAlias=%s\nstoreFile=%s' $(Store.Password) $(KeyStore.Password) $(KeyStore.KeyAlias) ../$(KeyStore.Name) > keystore.properties
    displayName: Generate keystore.properties

使用命令“:app:bundleRelease”执行任务 Gradle@2 后,生成的 aab 通过 gradle 签名配置进行签名。 然后我得到这个 aab 并将其发布到artifactory,如下所示:

- task: CopyFiles@2
  inputs:
    contents: |
      **/outputs/**/*.aab
    targetFolder: '$(build.artifactStagingDirectory)'
    displayName: Copy and .aab files to artifact staging directory
 - task: PublishBuildArtifacts@1
   inputs:
     pathToPublish: '$(build.artifactStagingDirectory)'
     artifactName: 'drop'
    displayName: Publish artifacts directory

2
投票

请简单问一个问题。天蓝色变量中 KeyStoreFile.secureFilePath 的值是多少

© www.soinside.com 2019 - 2024. All rights reserved.