Class: Fastlane::Actions::GradleAction
- Inherits:
-
Fastlane::Action
- Object
- Fastlane::Action
- Fastlane::Actions::GradleAction
- Defined in:
- fastlane/lib/fastlane/actions/gradle.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Fastlane::Action
Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
- .return_value ⇒ Object
Class Method Summary collapse
Methods inherited from Fastlane::Action
action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text
Class Method Details
.authors ⇒ Object
165 166 167 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 165 def self. ['KrauseFx', 'lmirosevic'] end |
.available_options ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 92 def self. [ FastlaneCore::ConfigItem.new(key: :task, env_name: 'FL_GRADLE_TASK', description: 'The gradle task you want to execute, e.g. `assemble` or `test`. For tasks such as `assembleMyFlavorRelease` you should use gradle(task: \'assemble\', flavor: \'Myflavor\', build_type: \'Release\')', optional: false, is_string: true), FastlaneCore::ConfigItem.new(key: :flavor, env_name: 'FL_GRADLE_FLAVOR', description: 'The flavor that you want the task for, e.g. `MyFlavor`. If you are running the `assemble` task in a multi-flavor project, and you rely on Actions.lane_context[Actions.SharedValues::GRADLE_APK_OUTPUT_PATH] then you must specify a flavor here or else this value will be undefined', optional: true, is_string: true), FastlaneCore::ConfigItem.new(key: :build_type, env_name: 'FL_GRADLE_BUILD_TYPE', description: 'The build type that you want the task for, e.g. `Release`. Useful for some tasks such as `assemble`', optional: true, is_string: true), FastlaneCore::ConfigItem.new(key: :flags, env_name: 'FL_GRADLE_FLAGS', description: 'All parameter flags you want to pass to the gradle command, e.g. `--exitcode --xml file.xml`', optional: true, is_string: true), FastlaneCore::ConfigItem.new(key: :project_dir, env_name: 'FL_GRADLE_PROJECT_DIR', description: 'The root directory of the gradle project', default_value: '.', is_string: true), FastlaneCore::ConfigItem.new(key: :gradle_path, env_name: 'FL_GRADLE_PATH', description: 'The path to your `gradlew`. If you specify a relative path, it is assumed to be relative to the `project_dir`', optional: true, is_string: true), FastlaneCore::ConfigItem.new(key: :properties, env_name: 'FL_GRADLE_PROPERTIES', description: 'Gradle properties to be exposed to the gradle script', optional: true, is_string: false), FastlaneCore::ConfigItem.new(key: :system_properties, env_name: 'FL_GRADLE_SYSTEM_PROPERTIES', description: 'Gradle system properties to be exposed to the gradle script', optional: true, is_string: false), FastlaneCore::ConfigItem.new(key: :serial, env_name: 'FL_ANDROID_SERIAL', description: 'Android serial, which device should be used for this command', is_string: true, default_value: ''), FastlaneCore::ConfigItem.new(key: :print_command, env_name: 'FL_GRADLE_PRINT_COMMAND', description: 'Control whether the generated Gradle command is printed as output before running it (true/false)', is_string: false, default_value: true), FastlaneCore::ConfigItem.new(key: :print_command_output, env_name: 'FL_GRADLE_PRINT_COMMAND_OUTPUT', description: 'Control whether the output produced by given Gradle command is printed while running (true/false)', is_string: false, default_value: true) ] end |
.category ⇒ Object
229 230 231 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 229 def self.category :building end |
.description ⇒ Object
82 83 84 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 82 def self.description 'All gradle related actions, including building and testing your Android app' end |
.details ⇒ Object
86 87 88 89 90 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 86 def self.details [ 'Run `./gradlew tasks` to get a list of all available gradle tasks for your project' ].join("\n") end |
.example_code ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 173 def self.example_code [ 'gradle( task: "assemble", flavor: "WorldDomination", build_type: "Release" )', 'gradle( # ... properties: { "versionCode" => 100, "versionName" => "1.0.0", # ... } ) ``` You can use this to automatically [sign and zipalign](https://developer.android.com/studio/publish/app-signing.html) your app: ```ruby gradle( task: "assemble", build_type: "Release", print_command: false, properties: { "android.injected.signing.store.file" => "keystore.jks", "android.injected.signing.store.password" => "store_password", "android.injected.signing.key.alias" => "key_alias", "android.injected.signing.key.password" => "key_password", } )', '# If you need to pass sensitive information through the `gradle` action, and don\'t want the generated command to be printed before it is run, you can suppress that: gradle( # ... print_command: false ) ``` You can also suppress printing the output generated by running the generated Gradle command: ```ruby gradle( # ... print_command_output: false ) ``` To pass any other CLI flags to gradle use: ```ruby gradle( # ... flags: "--exitcode --xml file.xml" )' ] end |
.is_supported?(platform) ⇒ Boolean
169 170 171 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 169 def self.is_supported?(platform) [:ios, :android].include?(platform) # we support iOS as cross platforms apps might want to call `gradle` also end |
.output ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 152 def self.output [ ['GRADLE_APK_OUTPUT_PATH', 'The path to the newly generated apk file. Undefined in a multi-variant assemble scenario'], ['GRADLE_ALL_APK_OUTPUT_PATHS', 'When running a multi-variant `assemble`, the array of signed apk\'s that were generated'], ['GRADLE_FLAVOR', 'The flavor, e.g. `MyFlavor`'], ['GRADLE_BUILD_TYPE', 'The build type, e.g. `Release`'] ] end |
.return_value ⇒ Object
161 162 163 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 161 def self.return_value 'The output of running the gradle task' end |
.run(params) ⇒ Object
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'fastlane/lib/fastlane/actions/gradle.rb', line 14 def self.run(params) task = params[:task] flavor = params[:flavor] build_type = params[:build_type] gradle_task = [task, flavor, build_type].join project_dir = params[:project_dir] gradle_path_param = params[:gradle_path] || './gradlew' # Get the path to gradle, if it's an absolute path we take it as is, if it's relative we assume it's relative to the project_dir gradle_path = if Pathname.new(gradle_path_param).absolute? File.(gradle_path_param) else File.(File.join(project_dir, gradle_path_param)) end # Ensure we ended up with a valid path to gradle UI.user_error!("Couldn't find gradlew at path '#{File.(gradle_path)}'") unless File.exist?(gradle_path) # Construct our flags flags = [] flags << "-p #{project_dir.shellescape}" flags << params[:properties].map { |k, v| "-P#{k.to_s.shellescape}=#{v.to_s.shellescape}" }.join(' ') unless params[:properties].nil? flags << params[:system_properties].map { |k, v| "-D#{k.to_s.shellescape}=#{v.to_s.shellescape}" }.join(' ') unless params[:system_properties].nil? flags << params[:flags] unless params[:flags].nil? # Run the actual gradle task gradle = Helper::GradleHelper.new(gradle_path: gradle_path) # If these were set as properties, then we expose them back out as they might be useful to others Actions.lane_context[SharedValues::GRADLE_BUILD_TYPE] = build_type if build_type Actions.lane_context[SharedValues::GRADLE_FLAVOR] = flavor if flavor # We run the actual gradle task result = gradle.trigger(task: gradle_task, serial: params[:serial], flags: flags.join(' '), print_command: params[:print_command], print_command_output: params[:print_command_output]) # If we didn't build, then we return now, as it makes no sense to search for apk's in a non-`assemble` scenario return result unless task =~ /\b(assemble)/ apk_search_path = File.join(project_dir, '**', 'build', 'outputs', 'apk', '**', '*.apk') # Our apk is now built, but there might actually be multiple ones that were built if a flavor was not specified in a multi-flavor project (e.g. `assembleRelease`), however we're not interested in unaligned apk's... new_apks = Dir[apk_search_path].reject { |path| path =~ /^.*-unaligned.apk$/i } new_apks = new_apks.map { |path| File.(path) } # We expose all of these new apk's Actions.lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = new_apks # We also take the most recent apk to return as SharedValues::GRADLE_APK_OUTPUT_PATH, this is the one that will be relevant for most projects that just build a single build variant (flavor + build type combo). In multi build variants this value is undefined last_apk_path = new_apks.sort_by(&File.method(:mtime)).last Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] = File.(last_apk_path) if last_apk_path # Give a helpful message in case there were no new apk's. Remember we're only running this code when assembling, in which case we certainly expect there to be an apk UI.('Couldn\'t find any new signed apk files...') if new_apks.empty? return result end |