[PR #9236/2b2872f0 backport][stable-10] Add android sdk module #9293
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #9236 as merged into main (2b2872f).
SUMMARY
This module allows to manage Android SDK packages
ISSUE TYPE
COMPONENT NAME
android_sdk
ADDITIONAL INFORMATION
This module uses
sdkmanager
binary, which is used to install Android SDK packages. Usually, Android SDK packages are installed by Android developers using Android Studio IDE, but in case when a server needs to be set up to be used as a CI/CD runner to build Android applications,sdkmanager
command line tool is used instead.In order to use this module,
sdkmanager
binary must be present on the target machine. The official way of installingsdkmanager
is described here: https://developer.android.com/tools/sdkmanagerThere is one caveat I'm not entirely sure how/whether to fix. For some of the packages installed with
sdkmanager
a license must be accepted beforehand. The accepted licenses are placed inside the directory containing Android SDK, in a subdirectorylicenses
as a file containing a single string:[vagrant@alma licenses]$ pwd /usr/local/android/sdk/licenses [vagrant@alma licenses]$ ls android-googletv-license android-sdk-preview-license android-sdk-arm-dbt-license google-gdk-license android-sdk-license mips-android-sysimage-license [vagrant@alma licenses]$ cat android-sdk-license 24333f8a63b6825ea9c5514f83c2829b004d1fee
There are three ways how a license may be accepted
sdkmanager
sees that the license for the package has not been accepted, a command line prompt will be displayed that the user is supposed to answer interactively.sdkmanager --licenses
command may be used. In this casesdkmanager
prints every license that has not been accepted sequentially and prompts the user after each one.licenses
subdirectory for any license that must be accepted (but IMO this is error-prone as there might be new licenses, which can't be known in advance).The easiest way to accept licenses from an Ansible playbook is to use the following task:
I haven't figured a straightforward way of how to accept licenses from inside the module. What I tried was to use
data
parameter ofmodule.run_command
function to sendy
to stdin, but the problem is that in case if we try to use the 2nd approach from the list above (sdkmanager --license
), thesdkmanager
tool prints multiple prompts for each license that is not accepted. Thedata
parameter sendsy
only to the first license prompt, but the remaining prompts hang the module as they are waiting for the user input. Another idea was to usedata='y'
every time a package is installed (1st approach), but this may also lead to the module hanging as there might be several packages requested for installation, and if they belong to different licenses, this ends up the same way.So, I decided that the module assumes that all licenses are accepted in advance (this is reflected in the "Notes" section of the documentation).