Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement action to Download Universal APK from Google Play Console #485

Closed
AliSoftware opened this issue May 19, 2023 · 2 comments
Closed

Comments

@AliSoftware
Copy link
Contributor

AliSoftware commented May 19, 2023

This is the ruby code that adds that functionality to fastlane's Supply::Client client:

require 'supply'

# Maybe at some point we will submit a PR to fastlane to add this to the main features? (would need to wrap it into an action first)
module Supply
    ApkDownloadID = Struct.new(:package_name, :version_code, :download_id)

    class Client
        # @param [Fixnum] version_code
        #   Version code of the app bundle.
        # @return [Array<ApkDownloadID>]
        #
        def get_univeral_apk_list(package_name:, version_code:)
            result = call_google_api { client.list_generatedapks(package_name, version_code) }
        
            result.generated_apks.map do |row|
                ApkDownloadID.new(package_name, version_code, row.generated_universal_apk.download_id)
            end
        end

        # @param [Supply::ApkDownloadID] apk_id
        #   The ApkDownloadID retrieved from `get_univeral_apk_list`
        # @param [IO, String] destination
        #   IO stream or filename to receive content download
        #
        def download_univeral_apk(apk_id:, destination:)
            call_google_api {
                client.download_generatedapk(apk_id.package_name, apk_id.version_code, apk_id.download_id, download_dest: destination)
            }
        end
    end
end

Example usage for Tumblr Android:

PLAY_STORE_JSON_KEY = File.join('.configure-files', 'push2play-key.json')
PACKAGE_NAME = 'com.tumblr'
version_code = 1290600109

client = File.open(PLAY_STORE_JSON_KEY) do |io|
    Supply::Client.new(service_account_json: io, params: { timeout: 5 })
end
universal_apks = client.get_univeral_apk_list(package_name: PACKAGE_NAME, version_code: version_code)
universal_apks.each do |apk|
    dest = File.join(Dir.home, 'Downloads', "#{apk.package_name}-universal-#{apk.version_code}.apk")
    puts "Downloading #{dest}..."
    client.download_univeral_apk(apk_id: apk, destination: dest)
    puts "Done."
end

We need to turn that code into a Fastlane action that would:

  • Take a package_name, version_code, json_key and destination input parameters (ConfigItems)
  • Call the code above, improving it to add error handling, and auto-retry (especially in case we call this too soon after having uploaded the corresponding AAB if GPC haven't had time to generate the APK from it just yet), etc.

p1684504716992959-slack-C02KLTL3MKM

@AliSoftware
Copy link
Contributor Author

I've now opened a PR in the fastlane repo to propose that new action to be included directly in fastlane itself 🎉

@AliSoftware
Copy link
Contributor Author

My new download_apk_from_google_play action has been shipped in fastlane 2.214.0; we can thus close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant