Google Play publishing

AppRelease uploads the app bundle to a Google Play track with a service account you create once in Google Cloud.

Requirements

  • The app exists in Google Play Console and the first bundle was uploaded by hand. Google requires that; every bundle after it can go through AppRelease.
  • The bundle is signed with the upload key (see Android code signing).

Creating a service account

  1. In the Google Cloud Console, choose or create a project and open IAM & Admin → Service accounts.
  2. Click Create service account, name it (for example "apprelease-publisher") and finish without granting project roles.
  3. Open the account, go to Keys → Add key → Create new key → JSON. The file downloads once.
  4. Still in the Cloud Console, open APIs & Services → Library, search for Google Play Android Developer API and press Enable. Without it every call is refused with "API has not been used in project … or it is disabled".
  5. In Google Play Console, open Users and permissions → Invite new users, enter the service account's email address and grant it Release to production, exclude devices, and use Play App Signing and Release apps to testing tracks for the app. Admin is not needed.
It can take a few minutes, sometimes longer, before Google Play accepts calls from a freshly invited account. A "The current user has insufficient permissions" error on the first release is usually just that.

Storing the key in AppRelease

  1. In the console open Credentials → Add credential → Google Play service account.
  2. Pick the JSON file, or paste its contents. The form then shows the service account's email to invite in Play Console.
  3. Keep the reference name google_play, or choose your own. It is the name apprelease.yaml would list under groups.
  4. Click Save, then Check on the saved credential: it calls Google and says which step, if any, is still missing.

During a build the JSON is available to the scripts as GOOGLE_PLAY_SERVICE_ACCOUNT and masked in the log. Without an apprelease.yaml, the runner uses the service account linked to the application, or the shared one.

Configuration

workflows:
  android-workflow:
    environment:
      groups:
        - google_play
    publishing:
      google_play:
        credentials: $GOOGLE_PLAY_SERVICE_ACCOUNT
        track: internal            # internal | alpha | beta | production | a custom track
        submit_as_draft: false     # true while the app is still in draft
        rollout_fraction: 0.1      # optional staged rollout on production
        in_app_update_priority: 0  # optional, 0–5
        changes_not_sent_for_review: false
KeyDefaultDescription
credentials—The service account JSON, by variable reference.
trackinternalWhere the release lands.
submit_as_draftfalseRequired while the app has never been published.
rollout_fraction—Staged rollout, 0.01–0.99. Omit for 100 %.
in_app_update_priority0Priority shown to the in-app updates API.
changes_not_sent_for_reviewfalseUpload without sending the change for review.

Release notes

Put a release_notes.txt, or release_notes_en-US.txt and friends, in the repository root. They are attached to the track release in the matching languages.

Common errors

MessageUsually means
Version code 57 has already been usedUse versioning: source: google_play so the build number comes from the store.
Only releases with status draft may be created on draft appAdd submit_as_draft: true.
The Android App Bundle was signed with the wrong keyThe keystore is not the upload key. See checking the signature.
Service account key creation is disabled (iam.disableServiceAccountKeyCreation)Your Google account belongs to a company organization, and new organizations block service-account keys by default. An organization admin switches it off: select the organization in the project picker → IAM & Admin → Organization Policies → "Disable service account key creation" → Manage policy → Override parent's policy → Enforcement off. Or create the Cloud project from a personal Gmail account instead: any project works, it need not be the one that owns Play Console.
Google Play Android Developer API has not been used in project … or it is disabledEnable that API in the Cloud project that owns the service account (step 4 above), then wait a minute.