androidazureazure-devopsazure-pipelines

How to Generate .AAB file and Sign Android app Bundle using azure pipeline


I want to generate an Android app bundle(.aab) file using the Azure pipeline and facing an issue while generating the Android App Bundle file.

I have used the below Gradle task to generate and sign the .aab file. but, It generating the .APK file. I want to generate .aab file.

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

Here is the script, Where I use jarsigner to sign the .aab file:

- 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)'

Solution

  • In the Gradle tasks: I needed to change the tasks value 'buildRelease' to ':app:bundleRelease' to generate the .aab file.

    Here is the .yaml file which I used to generate and sign .aab file:

    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'
    

    There is below variables that I created and used in the signing task:

    KeyStoreFile.secureFilePath
    StorePassword
    KeyPassword
    KeyStoreAlias