fastlane-plugin-bundletool 1.0.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +29 -15
- data/lib/fastlane/plugin/bundletool/actions/bundletool_action.rb +55 -54
- data/lib/fastlane/plugin/bundletool/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2beec5bfb2d18b0204a6818f4cc811b598d2453712b8c459150c2718e4247f6f
         | 
| 4 | 
            +
              data.tar.gz: fdef06f79576b285814a231beeca51059d5c6a65ad56181f1bebadacb2e131d9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7f34ea0842d770fcbe88d39f9b776b4eda9179c6337394a178827791a3cf4fe10387b6b3c1e4e137c9dba5e7d2e10546f02456e5298bd5c5c2c9fa3120c66fac
         | 
| 7 | 
            +
              data.tar.gz: e63256fe509d81b64fd7cf4c79abd3870f78d1db106badd16fc3988a213284546a1db885c409ce7ad8943996682842da3d3681261b3bc02c1d34a8da85111ac3
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            #  | 
| 1 | 
            +
            # Bundletool for Fastlane
         | 
| 2 2 |  | 
| 3 3 | 
             
            [](https://rubygems.org/gems/fastlane-plugin-bundletool)
         | 
| 4 4 |  | 
| @@ -10,30 +10,44 @@ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To | |
| 10 10 | 
             
            fastlane add_plugin bundletool
         | 
| 11 11 | 
             
            ```
         | 
| 12 12 |  | 
| 13 | 
            -
             | 
| 13 | 
            +
            or in your Pluginfile under fastlane folder write the following line and run `bundle install`.
         | 
| 14 14 |  | 
| 15 | 
            -
             | 
| 15 | 
            +
            ```
         | 
| 16 | 
            +
            gem 'fastlane-plugin-bundletool', '1.0.2'
         | 
| 17 | 
            +
            ```
         | 
| 16 18 |  | 
| 17 | 
            -
             | 
| 19 | 
            +
            ## About bundletool
         | 
| 18 20 |  | 
| 19 | 
            -
             | 
| 21 | 
            +
            **bundletool** is the underlying tool that Gradle, Android Studio, and Google Play use to build an Android App Bundle or convert an app bundle into the various APKs that are deployed to devices. bundletool is also available to you as a command line tool, so you can recreate, inspect, and verify Google Play’s server-side build of your app’s APKs.
         | 
| 20 22 |  | 
| 21 | 
            -
             | 
| 23 | 
            +
            https://developer.android.com/studio/command-line/bundletool
         | 
| 22 24 |  | 
| 23 | 
            -
             | 
| 25 | 
            +
            The motivation of this plugin is to extract an universal `.apk` file from an [.aab](https://fileinfo.com/extension/aab) file. Since we cannot distribute aab files, it's great that we can extract from the very same binary a file that we can distribute internally.
         | 
| 24 26 |  | 
| 25 | 
            -
            ##  | 
| 27 | 
            +
            ## Usage
         | 
| 26 28 |  | 
| 27 | 
            -
             | 
| 29 | 
            +
            In your Fastfile you need to use `bundletool` action. After you build the `.aab` file you can run the following code.
         | 
| 28 30 |  | 
| 29 | 
            -
            ```
         | 
| 30 | 
            -
             | 
| 31 | 
            +
            ```ruby
         | 
| 32 | 
            +
            bundletool(
         | 
| 33 | 
            +
              ks_path: keystore_path,
         | 
| 34 | 
            +
              ks_password: keystore_password,
         | 
| 35 | 
            +
              ks_key_alias: keystore_alias,
         | 
| 36 | 
            +
              ks_key_alias_password: keystore_alias_password,
         | 
| 37 | 
            +
              bundletool_version: '0.11.0',
         | 
| 38 | 
            +
              aab_path: aab_path,
         | 
| 39 | 
            +
              apk_output_path: apk_output_path,
         | 
| 40 | 
            +
              verbose: true
         | 
| 41 | 
            +
            )
         | 
| 31 42 | 
             
            ```
         | 
| 32 43 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 44 | 
            +
            This will output the universal `.apk` in the output path you set.
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            ## Use case
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            Here you can find a post I did explaining why I have to create this action.
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            https://medium.com/@gonzalez.martin90/bundletool-with-fastlane-8f8862ab16e0
         | 
| 37 51 |  | 
| 38 52 | 
             
            ## Issues and Feedback
         | 
| 39 53 |  | 
| @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'fastlane/action'
         | 
| 2 4 | 
             
            require_relative '../helper/bundletool_helper'
         | 
| 3 5 |  | 
| @@ -10,7 +12,7 @@ module Fastlane | |
| 10 12 | 
             
                    @bundletool_temp_path = "#{@project_root}/bundletool_temp"
         | 
| 11 13 | 
             
                    @verbose = params[:verbose]
         | 
| 12 14 | 
             
                    keystore_info = {}
         | 
| 13 | 
            -
                    unless  | 
| 15 | 
            +
                    unless params[:ks_path].nil?
         | 
| 14 16 | 
             
                      keystore_info[:keystore_path] = params[:ks_path]
         | 
| 15 17 | 
             
                      keystore_info[:keystore_password] = params[:ks_password]
         | 
| 16 18 | 
             
                      keystore_info[:alias] = params[:ks_key_alias]
         | 
| @@ -19,45 +21,48 @@ module Fastlane | |
| 19 21 |  | 
| 20 22 | 
             
                    bundletool_version = params[:bundletool_version]
         | 
| 21 23 | 
             
                    aab_path = params[:aab_path]
         | 
| 22 | 
            -
                    output_path = params[:apk_output_path]
         | 
| 24 | 
            +
                    output_path = params[:apk_output_path] || '.'
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    return unless validate_aab!(aab_path)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    return unless download_bundletool(bundletool_version)
         | 
| 23 29 |  | 
| 24 | 
            -
                    validate_aab!(aab_path) 
         | 
| 25 | 
            -
                    download_bundletool(bundletool_version)
         | 
| 26 30 | 
             
                    extract_universal_apk_from(aab_path, output_path, keystore_info)
         | 
| 27 31 | 
             
                  end
         | 
| 28 32 |  | 
| 29 33 | 
             
                  def self.validate_aab!(aab_path)
         | 
| 30 34 | 
             
                    puts_message('Checking if .aab file exists...')
         | 
| 31 | 
            -
                     | 
| 35 | 
            +
                    unless File.file?(aab_path)
         | 
| 36 | 
            +
                      puts_error!(".aab file at #{aab_path} does not exist")
         | 
| 37 | 
            +
                      return false
         | 
| 38 | 
            +
                    end
         | 
| 32 39 | 
             
                    puts_success('Checking if .aab file exists')
         | 
| 33 40 | 
             
                  end
         | 
| 34 41 |  | 
| 35 42 | 
             
                  def self.download_bundletool(version)
         | 
| 36 | 
            -
                     | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
                      open(" | 
| 40 | 
            -
                         | 
| 41 | 
            -
                          file.write(bundletool.read)
         | 
| 42 | 
            -
                        end
         | 
| 43 | 
            +
                    puts_message("Downloading bundletool (#{version}) from https://github.com/google/bundletool/releases/download/#{version}/bundletool-all-#{version}.jar...")
         | 
| 44 | 
            +
                    Dir.mkdir "#{@project_root}/bundletool_temp"        
         | 
| 45 | 
            +
                    URI.open("https://github.com/google/bundletool/releases/download/#{version}/bundletool-all-#{version}.jar") do |bundletool|
         | 
| 46 | 
            +
                      File.open("#{@bundletool_temp_path}/bundletool.jar", 'wb') do |file|
         | 
| 47 | 
            +
                        file.write(bundletool.read)
         | 
| 43 48 | 
             
                      end
         | 
| 44 | 
            -
                      puts_success('Downloading bundletool')
         | 
| 45 | 
            -
                    rescue StandardError => e
         | 
| 46 | 
            -
                      puts_error!("Something went wrong when downloading bundletool version #{version}")
         | 
| 47 49 | 
             
                    end
         | 
| 50 | 
            +
                    puts_success('Downloading bundletool')
         | 
| 51 | 
            +
                  rescue OpenURI::HTTPError => e
         | 
| 52 | 
            +
                    clean_temp!
         | 
| 53 | 
            +
                    puts_error!("Something went wrong when downloading bundletool version #{version}. \nError message\n #{e.message}")        
         | 
| 54 | 
            +
                    false
         | 
| 48 55 | 
             
                  end
         | 
| 49 56 |  | 
| 50 57 | 
             
                  def self.extract_universal_apk_from(aab_path, apk_output_path, keystore_info)
         | 
| 51 | 
            -
                     | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
                     | 
| 57 | 
            -
             | 
| 58 | 
            -
                     | 
| 59 | 
            -
                      clean_temp!
         | 
| 60 | 
            -
                    end
         | 
| 58 | 
            +
                    aab_absolute_path = Pathname.new(File.expand_path(aab_path)).to_s
         | 
| 59 | 
            +
                    apk_output_absolute_path = Pathname.new(File.expand_path(apk_output_path)).to_s
         | 
| 60 | 
            +
                    output_path = run_bundletool!(aab_absolute_path, keystore_info)
         | 
| 61 | 
            +
                    prepare_apk!(output_path, apk_output_absolute_path)
         | 
| 62 | 
            +
                  rescue StandardError => e
         | 
| 63 | 
            +
                    puts_error!("Bundletool could not extract universal apk from aab at #{aab_absolute_path}. \nError message\n #{e.message}")
         | 
| 64 | 
            +
                  ensure
         | 
| 65 | 
            +
                    clean_temp!
         | 
| 61 66 | 
             
                  end
         | 
| 62 67 |  | 
| 63 68 | 
             
                  def self.run_bundletool!(aab_path, keystore_info)
         | 
| @@ -65,18 +70,11 @@ module Fastlane | |
| 65 70 | 
             
                    output_path = "#{@bundletool_temp_path}/output.apks"
         | 
| 66 71 | 
             
                    keystore_params = ''
         | 
| 67 72 |  | 
| 68 | 
            -
                    unless  | 
| 69 | 
            -
                      keystore_params = "--ks | 
| 70 | 
            -
                      --ks-pass=pass:#{keystore_info[:keystore_password]} \
         | 
| 71 | 
            -
                      --ks-key-alias=#{keystore_info[:alias]} \
         | 
| 72 | 
            -
                      --key-pass=pass:#{keystore_info[:alias_password]}"
         | 
| 73 | 
            +
                    unless keystore_info.empty?
         | 
| 74 | 
            +
                      keystore_params = "--ks=\"#{keystore_info[:keystore_path]}\" --ks-pass=\"pass:#{keystore_info[:keystore_password]}\" --ks-key-alias=\"#{keystore_info[:alias]}\" --key-pass=\"pass:#{keystore_info[:alias_password]}\""
         | 
| 73 75 | 
             
                    end
         | 
| 74 76 |  | 
| 75 | 
            -
                    cmd = "java -jar #{@bundletool_temp_path}/bundletool.jar build-apks \
         | 
| 76 | 
            -
                    --bundle=#{aab_path} \
         | 
| 77 | 
            -
                    --output=#{output_path} \
         | 
| 78 | 
            -
                    --mode=universal \
         | 
| 79 | 
            -
                    #{keystore_params}"
         | 
| 77 | 
            +
                    cmd = "java -jar #{@bundletool_temp_path}/bundletool.jar build-apks --bundle=\"#{aab_path}\" --output=\"#{output_path}\" --mode=universal #{keystore_params}"
         | 
| 80 78 |  | 
| 81 79 | 
             
                    Open3.popen3(cmd) do |_, _, stderr, wait_thr|
         | 
| 82 80 | 
             
                      exit_status = wait_thr.value
         | 
| @@ -88,15 +86,17 @@ module Fastlane | |
| 88 86 |  | 
| 89 87 | 
             
                  def self.prepare_apk!(output_path, target_path)
         | 
| 90 88 | 
             
                    puts_message("Preparing apk to #{target_path}...")
         | 
| 91 | 
            -
                     | 
| 89 | 
            +
                    if File.file?(target_path)
         | 
| 90 | 
            +
                      puts_important("Apk at path #{target_path} exists. Replacing it.")
         | 
| 91 | 
            +
                    end
         | 
| 92 92 | 
             
                    target_dir_name = File.dirname(target_path)
         | 
| 93 93 | 
             
                    unless Dir.exist?(target_dir_name)
         | 
| 94 | 
            -
                      puts_important("Creating path #{ | 
| 95 | 
            -
                       | 
| 94 | 
            +
                      puts_important("Creating path #{target_dir_name} since does not exist")
         | 
| 95 | 
            +
                      FileUtils.mkdir_p target_dir_name
         | 
| 96 96 | 
             
                    end
         | 
| 97 | 
            -
                    cmd = "mv #{output_path} #{@bundletool_temp_path}/output.zip &&
         | 
| 98 | 
            -
                    unzip #{@bundletool_temp_path}/output.zip -d #{@bundletool_temp_path} &&
         | 
| 99 | 
            -
                    mv #{@bundletool_temp_path}/universal.apk #{target_path}"
         | 
| 97 | 
            +
                    cmd = "mv \"#{output_path}\" \"#{@bundletool_temp_path}/output.zip\" &&
         | 
| 98 | 
            +
                    unzip \"#{@bundletool_temp_path}/output.zip\" -d \"#{@bundletool_temp_path}\" &&
         | 
| 99 | 
            +
                    mv \"#{@bundletool_temp_path}/universal.apk\" \"#{target_path}\""
         | 
| 100 100 | 
             
                    Open3.popen3(cmd) do |_, _, stderr, wait_thr|
         | 
| 101 101 | 
             
                      exit_status = wait_thr.value
         | 
| 102 102 | 
             
                      raise stderr.read unless exit_status.success?
         | 
| @@ -104,7 +104,7 @@ module Fastlane | |
| 104 104 | 
             
                    puts_success("Preparing apk to #{target_path}")
         | 
| 105 105 | 
             
                  end
         | 
| 106 106 |  | 
| 107 | 
            -
                  def self.clean_temp! | 
| 107 | 
            +
                  def self.clean_temp!
         | 
| 108 108 | 
             
                    cmd = "rm -rf #{@project_root}/bundletool_temp"
         | 
| 109 109 | 
             
                    Open3.popen3(cmd) do |_, _, stderr, wait_thr|
         | 
| 110 110 | 
             
                      exit_status = wait_thr.value
         | 
| @@ -117,14 +117,19 @@ module Fastlane | |
| 117 117 | 
             
                  end
         | 
| 118 118 |  | 
| 119 119 | 
             
                  def self.puts_success(message)
         | 
| 120 | 
            -
                     | 
| 120 | 
            +
                    if @verbose
         | 
| 121 | 
            +
                      UI.success "#{message} #{Fastlane::Helper::Emojis.green_checkmark}"
         | 
| 122 | 
            +
                    end
         | 
| 121 123 | 
             
                  end
         | 
| 122 124 |  | 
| 123 125 | 
             
                  def self.puts_important(message)
         | 
| 124 | 
            -
                     | 
| 126 | 
            +
                    if @verbose
         | 
| 127 | 
            +
                      UI.important "#{message} #{Fastlane::Helper::Emojis.warning}"
         | 
| 128 | 
            +
                    end
         | 
| 125 129 | 
             
                  end
         | 
| 126 130 |  | 
| 127 131 | 
             
                  def self.puts_error!(message)
         | 
| 132 | 
            +
                    p message
         | 
| 128 133 | 
             
                    UI.user_error! message
         | 
| 129 134 | 
             
                  end
         | 
| 130 135 |  | 
| @@ -162,12 +167,8 @@ module Fastlane | |
| 162 167 | 
             
                      FastlaneCore::ConfigItem.new(key: :apk_output_path,
         | 
| 163 168 | 
             
                                                   description: 'Path where the apk file is going to be placed',
         | 
| 164 169 | 
             
                                                   is_string: true,
         | 
| 165 | 
            -
                                                   optional:  | 
| 166 | 
            -
                                                    | 
| 167 | 
            -
                                                                   unless value && !value.empty?
         | 
| 168 | 
            -
                                                                     UI.user_error!('You must set apk_output_path.')
         | 
| 169 | 
            -
                                                                   end
         | 
| 170 | 
            -
                                                                 end),
         | 
| 170 | 
            +
                                                   optional: true,
         | 
| 171 | 
            +
                                                   default_value: '.'),
         | 
| 171 172 | 
             
                      FastlaneCore::ConfigItem.new(key: :verbose,
         | 
| 172 173 | 
             
                                                   description: 'Show every messages of the action',
         | 
| 173 174 | 
             
                                                   is_string: false,
         | 
| @@ -181,20 +182,20 @@ module Fastlane | |
| 181 182 | 
             
                  def self.print_params(options)
         | 
| 182 183 | 
             
                    table_title = "Params for bundletool #{Fastlane::Bundletool::VERSION}"
         | 
| 183 184 | 
             
                    FastlaneCore::PrintTable.print_values(config: options,
         | 
| 184 | 
            -
                                                          mask_keys: [ | 
| 185 | 
            +
                                                          mask_keys: %i[ks_password ks_key_alias_password],
         | 
| 185 186 | 
             
                                                          title: table_title)
         | 
| 186 187 | 
             
                  end
         | 
| 187 188 |  | 
| 188 189 | 
             
                  def self.description
         | 
| 189 | 
            -
                     | 
| 190 | 
            +
                    'Extracts an universal apk from an .aab file'
         | 
| 190 191 | 
             
                  end
         | 
| 191 192 |  | 
| 192 193 | 
             
                  def self.authors
         | 
| 193 | 
            -
                    [ | 
| 194 | 
            +
                    ['Martin Gonzalez']
         | 
| 194 195 | 
             
                  end
         | 
| 195 196 |  | 
| 196 197 | 
             
                  def self.details
         | 
| 197 | 
            -
                     | 
| 198 | 
            +
                    'Using the google oficial bundletool to extract an universal apk from .aab file to distribute it'
         | 
| 198 199 | 
             
                  end
         | 
| 199 200 |  | 
| 200 201 | 
             
                  def self.is_supported?(platform)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fastlane-plugin-bundletool
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Martin Gonzalez
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-08-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: pry
         | 
| @@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 168 168 | 
             
                - !ruby/object:Gem::Version
         | 
| 169 169 | 
             
                  version: '0'
         | 
| 170 170 | 
             
            requirements: []
         | 
| 171 | 
            -
            rubygems_version: 3.0.3
         | 
| 171 | 
            +
            rubygems_version: 3.0.3.1
         | 
| 172 172 | 
             
            signing_key: 
         | 
| 173 173 | 
             
            specification_version: 4
         | 
| 174 174 | 
             
            summary: Extracts a universal apk from an .aab file
         |