Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload app bundle (.aab) to play store using Google Play Publisher API

I have configured and used API to upload .apk files and it is working perfectly using this code file.

    """Uploads an apk to the alpha track."""

import argparse
import sys
from apiclient import sample_tools
from oauth2client import client

TRACK = 'alpha'  # Can be 'alpha', beta', 'production' or 'rollout'

# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('package_name',
                       help='The package name. Example: com.android.sample')
argparser.add_argument('apk_file',
                       nargs='?',
                       default='test.apk',
                       help='The path to the APK file to upload.')


def main(argv):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      argv,
      'androidpublisher',
      'v3',
      __doc__,
      __file__, parents=[argparser],
      scope='https://www.googleapis.com/auth/androidpublisher')

  # Process flags and read their values.
  package_name = flags.package_name
  apk_file = flags.apk_file

  try:
    edit_request = service.edits().insert(body={}, packageName=package_name)
    result = edit_request.execute()
    edit_id = result['id']

    apk_response = service.edits().apks().upload(
        editId=edit_id,
        packageName=package_name,
        media_body=apk_file).execute()

    print 'Version code %d has been uploaded' % apk_response['versionCode']

    track_response = service.edits().tracks().update(
        editId=edit_id,
        track=TRACK,
        packageName=package_name,
        body={u'releases': [{
            u'name': u'My first API release',
            u'versionCodes': [str(apk_response['versionCode'])],
            u'status': u'completed',
        }]}).execute()

    print 'Track %s is set with releases: %s' % (
        track_response['track'], str(track_response['releases']))

    commit_request = service.edits().commit(
        editId=edit_id, packageName=package_name).execute()

    print 'Edit "%s" has been committed' % (commit_request['id'])

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')

if __name__ == '__main__':
  main(sys.argv)

But this code does not work for app bundles.

like image 264
hard coder Avatar asked Apr 09 '19 09:04

hard coder


People also ask

How do I download app bundles from Google Play?

Download device-specific APKsOpen the App bundle explorer page (Release > Devices and versions > App bundle explorer). Select the version filter near the top right of the page. On the “Choose a version” table, select the right arrow on the version that you want to view. Select the Downloads tab.

What is AaB (Android app bundle)?

Android App Bundle ( AAB) is a new upload format that includes all your app’s compiled code and resources, but defers APK generation and signing to Google Play using Google’s app serving model called Dynamic Delivery.

How to push release APK/AaB file to Google Play Store?

Another key needed to push/upload the app’s release apk/aab file to Google Play Store is something called Upload key; we need to sign our app’s binary with an Upload key. i.e our app’s apk/aab should also be generated with an additional file having a digital code called Upload key.

How do I upload an Android app bundle to Google Play?

If you build and upload an Android App Bundle, you must enroll in app Play App Signing. Google Play supports compressed app downloads of only 150 MB or less. To learn more, read Compressed download size restriction. After you've met the requirements above, go ahead and upload your app to the Play Console .

How do I publish my app to Google Play Store?

After you build and sign the release version of your app , the next step is to upload it to Google Play to inspect, test, and publish your app. Before you get started, you might want to make sure you satisfy the following: If you haven't already done so, enroll into Play App Signing, which is the recommended way to upload and sign your app.


2 Answers

If googleapiclient.errors.UnknownFileType exception occurs, try adding the following code:

import mimetypes

mimetypes.add_type("application/octet-stream", ".apk")
mimetypes.add_type("application/octet-stream", ".aab")

And if socket.timeout exception occurs, try adding the following code:

import socket

socket.setdefaulttimeout(7 * 24 * 60 * 60)
like image 119
Joonsoo Avatar answered Oct 07 '22 21:10

Joonsoo


Google publishing API exposes bundles method. You can try following:

service.edits().bundles().upload(
        editId=edit_id,
        packageName=package_name,
        media_body=aab_file).execute()
like image 21
Rakesh Avatar answered Oct 07 '22 21:10

Rakesh