Skip to content

Instantly share code, notes, and snippets.

@zhgchgli0718
Created April 20, 2023 04:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhgchgli0718/42f6326225e393e20616ce15f3390c88 to your computer and use it in GitHub Desktop.
Save zhgchgli0718/42f6326225e393e20616ce15f3390c88 to your computer and use it in GitHub Desktop.
A simply extend the Fastlane Action to enable downloading the uploaded Universal APK from the Google Play Console.
# File location: /actions/apk_downloader.rb
module Fastlane
module Actions
module SharedValues
APK_DOWNLOADER_CUSTOM_VALUE = :APK_DOWNLOADER_CUSTOM_VALUE
end
class ApkDownloaderAction < Action
def self.run(params)
require 'supply'
require 'supply/options'
Supply.config = params
supplyClient = Supply::Client.make_from_config
googleClient = supplyClient.client
apks = googleClient.list_generatedapks(params[:package_name], params[:version_code])
downloadID = apks.generated_apks[0].generated_universal_apk.download_id
UI.message("ApkDownloaderAction...\npackageName: #{params[:package_name]}\nversionCode: #{params[:version_code]}\nDownloadID: #{downloadID}")
UI.message("🕗 Downloading APK...")
apk = googleClient.download_generatedapk(params[:package_name], params[:version_code], downloadID, download_dest: params[:export_file_path]) {
UI.success("✅ Successfully download apk in '#{params[:export_file_path]}'")
}
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Download generated Apk from google play console."
end
def self.details
"Download generated Apk from google play console."
end
def self.available_options
require 'supply'
require 'supply/options'
defaultOptions = [
:package_name,
:track,
:json_key,
:json_key_data,
:root_url,
:timeout,
:key,
:version_code
]
result = Supply::Options.available_options.select do |option|
defaultOptions.include?(option.key)
end
result.append(FastlaneCore::ConfigItem.new(key: :export_file_path,
env_name: "FL_APK_EXPORT_FILE_PATH",
description: "APK Export File Path",
is_string: true,
default_value: ""))
end
def self.output
[
]
end
def self.return_value
end
def self.authors
["zhgchgli"]
end
def self.is_supported?(platform)
platform == :android
end
end
end
end
lane :test do | options |
apk_downloader(json_key: "./xxx@xxx.iam.gserviceaccount.com.json", package_name: "m.zhgchg.li", version_code:1000, export_file_path: "./zhgchgli.apk")
end
@zhgchgli0718
Copy link
Author

image

@aBenVip
Copy link

aBenVip commented Sep 11, 2023

i receive "The following App Bundle version code could not be found." when i call list_generatedapks method,can you help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment