Class: Fastlane::Actions::FlutterBootstrapAction

Inherits:
Action
  • Object
show all
Extended by:
FlutterActionBase
Defined in:
lib/fastlane/plugin/flutter/actions/flutter_bootstrap_action.rb

Class Method Summary collapse

Methods included from FlutterActionBase

authors, is_supported?

Class Method Details

.android_sdk_root!Object



43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/flutter/actions/flutter_bootstrap_action.rb', line 43

def self.android_sdk_root!
  (ENV['ANDROID_HOME'] || ENV['ANDROID_SDK_ROOT']).tap do |path|
    unless path
      UI.build_failure!('Android SDK directory environment variables ' \
        'are not set. See ' \
        'https://developer.android.com/studio/command-line/variables')
    end
  end
end

.available_optionsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fastlane/plugin/flutter/actions/flutter_bootstrap_action.rb', line 57

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :flutter_channel,
      env_name: 'FL_FLUTTER_CHANNEL',
      description: 'Flutter SDK channel (keep existing if unset)',
      optional: true,
      type: String,
    ),
    FastlaneCore::ConfigItem.new(
      key: :android_licenses,
      description: 'Map of file names to hash values of accepted ' \
      'Android SDK linceses, which may be found in ' \
      '$ANDROID_SDK_ROOT/licenses/ on developer workstations. Gradle ' \
      'will refuse to install SDK unless licenses are accepted',
      optional: true,
      type: Hash,
    ),
  ]
end

.descriptionObject



53
54
55
# File 'lib/fastlane/plugin/flutter/actions/flutter_bootstrap_action.rb', line 53

def self.description
  'Flutter SDK installation, upgrade and application bootstrap'
end

.run(params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fastlane/plugin/flutter/actions/flutter_bootstrap_action.rb', line 11

def self.run(params)
  if params[:android_licenses]
    Helper::FlutterBootstrapHelper.accept_licenses(
      File.join(android_sdk_root!, 'licenses'),
      params[:android_licenses],
    )
  end

  # Upgrade or install Flutter SDK.
  flutter_sdk_root = Helper::FlutterHelper.flutter_sdk_root
  flutter_channel = params[:flutter_channel]
  if File.directory?(flutter_sdk_root)
    UI.message("Upgrading Flutter SDK in #{flutter_sdk_root}...")
    if flutter_channel
      UI.message("Making sure Flutter is on channel #{flutter_channel}")
      Helper::FlutterHelper.flutter('channel', flutter_channel) {}
    end
    Helper::FlutterHelper.flutter('upgrade') {}
  else
    Helper::FlutterHelper.git(
      'clone', # no --depth to keep Flutter tag-based versioning.
      "--branch=#{flutter_channel || 'beta'}",
      '--quiet',
      '--',
      'https://github.com/flutter/flutter.git',
      flutter_sdk_root,
    )
  end
  UI.message('Precaching Flutter SDK binaries...')
  Helper::FlutterHelper.flutter('precache') {}
end