Reputation: 2343
I have app using Play App Signing. I want upload app to Huawei App Gallery. Google recommend to download signed, universal APK from bundle explorer and then upload to store outside Google Play.
If you also distribute your app outside of Google Play or plan to later and want to use the same signing key, you have two options:
- Either let Google generate the key (recommended) and then download a signed, universal APK from the app bundle explorer to distribute outside of Google Play. You can also download signed APKs from the Google Play Developer API.
- Or you can generate the app signing key you want to use for every app store, and then transfer a copy of it to Google when you opt in to Play App Signing.
https://support.google.com/googleplay/android-developer/answer/9842756?hl=en
How I can automate this with Fastlane so I not need to manually download universal APK from bundle explorer every time?
Upvotes: 4
Views: 1374
Reputation: 4897
Using python you can do this:
import argparse
from apiclient.discovery import build
import httplib2
from oauth2client import client
from oauth2client.service_account import ServiceAccountCredentials
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('package_name',
help='The package name. Example: com.android.sample')
argparser.add_argument('key_file',
nargs='?',
default='key.p12',
help='The path to the p12 key file.')
argparser.add_argument('account_email',
nargs='?',
default='...',
help='service account email.')
def main():
flags = argparser.parse_args()
credentials = ServiceAccountCredentials.from_p12_keyfile(
flags.account_email,
flags.key_file,
scopes=['https://www.googleapis.com/auth/androidpublisher'])
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
package_name = flags.package_name
try:
edit_request = service.edits().insert(body={}, packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
apks_result = service.edits().apks().list(editId=edit_id, packageName=package_name).execute()
#https://googleapis.github.io/google-api-python-client/docs/dyn/androidpublisher_v3.html
generatedApks = service.generatedapks().list(packageName=package_name, versionCode= '200000').execute()
downloadId = generatedApks['generatedApks'][0]['generatedUniversalApk']['downloadId']
#pass versionCode
apkFile_media = service.generatedapks().download_media(packageName=package_name, versionCode= '200000', downloadId=downloadId).execute()
#put version on file name
file = open('app.apk', 'wb')
file.write(apkFile_media)
file.close()
Upvotes: 1
Reputation: 77
I suggest generating your own script using Google Play Store Developer API
This is the reference page https://developers.google.com/android-publisher/download-apks
You can follow this page to learn how you can generate the token for your download script https://developers.google.com/android-publisher/getting_started
Generating tokens might be a little tricky if you are not familiar with the process, but the rest of the process is easy,
Remember, you have to upload a bundle because there is no signed APK API if you upload an APK in step 3. Also, it is better when updating your edit to use the draft status in step 5, it enables you to test the signed APK before release. You can find the detail of all API in the link I have shared
Upvotes: 1