community.general.android_sdk module – Manages Android SDK packages

Note

This module is part of the community.general collection (version 10.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.android_sdk.

New in community.general 10.2.0

Synopsis

  • Manages Android SDK packages.

  • Allows installation from different channels (stable, beta, dev, canary).

  • Allows installation of packages to a non-default SDK root directory.

Requirements

The below requirements are needed on the host that executes this module.

  • java >= 17

  • sdkmanager Command line tool for installing Android SDK packages.

Parameters

Parameter

Comments

accept_licenses

boolean

If this is set to true, the module will try to accept license prompts generated by sdkmanager during package installation. Otherwise, every license prompt will be rejected.

Choices:

  • false ← (default)

  • true

channel

string

Indicates what channel must sdkmanager use for installation of packages.

Choices:

  • "stable" ← (default)

  • "beta"

  • "dev"

  • "canary"

name

aliases: package, pkg

list / elements=string

A name of an Android SDK package (for instance, build-tools;34.0.0).

sdk_root

path

Provides path for an alternative directory to install Android SDK packages to. By default, all packages are installed to the directory where sdkmanager is installed.

state

string

Indicates the desired package(s) state.

present ensures that package(s) is/are present.

absent ensures that package(s) is/are absent.

latest ensures that package(s) is/are installed and updated to the latest version(s).

Choices:

  • "present" ← (default)

  • "absent"

  • "latest"

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Notes

Note

  • For some of the packages installed by sdkmanager is it necessary to accept licenses. Usually it is done through command line prompt in a form of a Y/N question when a licensed package is requested to be installed. If there are several packages requested for installation and at least two of them belong to different licenses, the sdkmanager tool will prompt for these licenses in a loop. In order to install packages, the module must be able to answer these license prompts. Currently, it is only possible to answer one license prompt at a time, meaning that instead of installing multiple packages as a single invocation of the sdkmanager --install command, it will be done by executing the command independently for each package. This makes sure that at most only one license prompt will need to be answered. At the time of writing this module, a sdkmanager‘s package may belong to at most one license type that needs to be accepted. However, if this changes in the future, the module may hang as there might be more prompts generated by the sdkmanager tool which the module will not be able to answer. If this becomes the case, file an issue and in the meantime, consider accepting all the licenses in advance, as it is described in the sdkmanager documentation, for instance, using the ansible.builtin.command module.

See Also

See also

sdkmanager tool documentation

Detailed information of how to install and use sdkmanager command line tool.

Examples

- name: Install build-tools;34.0.0
  community.general.android_sdk:
    name: build-tools;34.0.0
    accept_licenses: true
    state: present

- name: Install build-tools;34.0.0 and platform-tools
  community.general.android_sdk:
    name:
      - build-tools;34.0.0
      - platform-tools
    accept_licenses: true
    state: present

- name: Delete build-tools;34.0.0
  community.general.android_sdk:
    name: build-tools;34.0.0
    state: absent

- name: Install platform-tools or update if installed
  community.general.android_sdk:
    name: platform-tools
    accept_licenses: true
    state: latest

- name: Install build-tools;34.0.0 to a different SDK root
  community.general.android_sdk:
    name: build-tools;34.0.0
    accept_licenses: true
    state: present
    sdk_root: "/path/to/new/root"

- name: Install a package from another channel
  community.general.android_sdk:
    name: some-package-present-in-canary-channel
    accept_licenses: true
    state: present
    channel: canary

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

installed

list / elements=string

A list of packages that have been installed.

Returned: when packages have changed

Sample: ["build-tools;34.0.0", "platform-tools"]

removed

list / elements=string

A list of packages that have been removed.

Returned: when packages have changed

Sample: ["build-tools;34.0.0", "platform-tools"]

Authors

  • Stanislav Shamilov (@shamilovstas)