build_android_app

Alias for the gradle action

Run ./gradlew tasks to get a list of all available gradle tasks for your project

build_android_app
Supported platforms ios, android
Author @KrauseFx, @lmirosevic
Returns The output of running the gradle task

1 Example

gradle(
  task: "assemble",
  flavor: "WorldDomination",
  build_type: "Release"
)

To build an AAB use:

gradle(
  task: "bundle",
  flavor: "WorldDomination",
  build_type: "Release"
)

You can pass multiple gradle tasks:

gradle(
  tasks: ["assembleDebug", "bundleDebug"]
)

You can pass properties to gradle:

gradle(
  # ...

  properties: {
    "exampleNumber" => 100,
    "exampleString" => "1.0.0",
    # ...
  }
)

You can use this to change the version code and name of your app:

gradle(
  # ...

  properties: {
    "android.injected.version.code" => 100,
    "android.injected.version.name" => "1.0.0",
    # ...
  }
)

You can use this to automatically sign and zipalign your app:

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:

gradle(
  # ...
  print_command_output: false
)

To pass any other CLI flags to gradle use:

gradle(
  # ...

  flags: "--exitcode --xml file.xml"
)

Delete the build directory, generated APKs and AABs

gradle(
  task: "clean"
)

Parameters

Key Description Default
task The gradle task you want to execute, e.g. assemble , bundle or test . For tasks such as assembleMyFlavorRelease you should use gradle(task: 'assemble', flavor: 'Myflavor', build_type: 'Release')
flavor 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[SharedValues::GRADLE_APK_OUTPUT_PATH] then you must specify a flavor here or else this value will be undefined
build_type The build type that you want the task for, e.g. Release . Useful for some tasks such as assemble
tasks The multiple gradle tasks that you want to execute, e.g. [assembleDebug, bundleDebug]
flags All parameter flags you want to pass to the gradle command, e.g. --exitcode --xml file.xml
project_dir The root directory of the gradle project .
gradle_path The path to your gradlew . If you specify a relative path, it is assumed to be relative to the project_dir
properties Gradle properties to be exposed to the gradle script
system_properties Gradle system properties to be exposed to the gradle script
serial Android serial, which device should be used for this command ''
print_command Control whether the generated Gradle command is printed as output before running it (true/false) true
print_command_output Control whether the output produced by given Gradle command is printed while running (true/false) true

* = default value is dependent on the user's system


Lane Variables

Actions can communicate with each other using a shared hash lane_context , that can be accessed in other actions, plugins or your lanes: lane_context[SharedValues:XYZ] . The build_android_app action generates the following Lane Variables:

SharedValue Description
SharedValues::GRADLE_APK_OUTPUT_PATH The path to the newly generated apk file. Undefined in a multi-variant assemble scenario
SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS When running a multi-variant assemble , the array of signed apk's that were generated
SharedValues::GRADLE_FLAVOR The flavor, e.g. MyFlavor
SharedValues::GRADLE_BUILD_TYPE The build type, e.g. Release
SharedValues::GRADLE_AAB_OUTPUT_PATH The path to the most recent Android app bundle
SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS The paths to the most recent Android app bundles
SharedValues::GRADLE_OUTPUT_JSON_OUTPUT_PATH The path to the most recent output.json file
SharedValues::GRADLE_ALL_OUTPUT_JSON_OUTPUT_PATHS The path to the newly generated output.json files
SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH The path to the most recent mapping.txt file
SharedValues::GRADLE_ALL_MAPPING_TXT_OUTPUT_PATHS The path to the newly generated mapping.txt files

To get more information check the Lanes documentation .


Documentation

To show the documentation in your terminal, run

fastlane action build_android_app

CLI

It is recommended to add the above action into your Fastfile , however sometimes you might want to run one-offs. To do so, you can run the following command from your terminal

fastlane run build_android_app

To pass parameters, make use of the : symbol, for example

fastlane run build_android_app parameter1:"value1" parameter2:"value2"

It's important to note that the CLI supports primitive types like integers, floats, booleans, and strings. Arrays can be passed as a comma delimited string (e.g. param:"1,2,3" ). Hashes are not currently supported.

It is recommended to add all fastlane actions you use to your Fastfile .


Source code

This action, just like the rest of fastlane , is fully open source, view the source code on GitHub


Back to actions