Files
env-ansible/tasks/workstation/linux/software/android.yml
2025-07-13 19:43:31 -07:00

306 lines
9.7 KiB
YAML

---
# Android Studio (and SDK?). Copied and adjusted from Flutter playbook.
# https://wiki.debian.org/AndroidStudio
# https://developer.android.com/studio/install
## Facts ##
# Studio download URLs:
# https://developer.android.com/studio/archive
# Current version:
# https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2024.2.2.14/android-studio-2024.2.2.14-linux.tar.gz
# Command-line tools is all Flutter actually needs:
# https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
- name: Workstation | Linux | Software | Android | Facts [1/3]
set_fact:
android_url: "https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip"
android_download_file: "{{ user_user.home }}/Downloads/android-cmdline-tools.tar.xz"
android_sdk_location: "{{ user_user.home }}/SDKs/Android/Sdk"
android_report_file: "{{ user_user.home }}/Reports/{{ ansible_hostname }}.sdk.android.txt"
- name: Workstation | Linux | Software | Android | Facts [2/3]
set_fact:
android_bin_location: "{{ android_sdk_location }}/platform-tools"
android_sdk_cmdline_temp: "{{ android_sdk_location }}/ansible"
android_sdk_cmdline_final: "{{ android_sdk_location }}/cmdline-tools/latest/bin"
- name: Workstation | Linux | Software | Android | Facts [3/3]
set_fact:
android_sdkmanager_temp: "{{ android_sdk_cmdline_temp }}/cmdline-tools/bin/sdkmanager"
android_sdkmanager_final: "{{ android_sdk_cmdline_final }}/sdkmanager"
## Checks ##
- name: Workstation | Linux | Software | Android | Check SDK Manager Exists [1/2]
stat:
path: "{{ android_sdkmanager_temp }}"
register: android_sdkmanager_temp_stat
when: coding == true
- name: Workstation | Linux | Software | Android | Check SDK Manager Exists [2/2]
stat:
path: "{{ android_sdkmanager_final }}"
register: android_sdkmanager_final_stat
when: coding == true
- name: Workstation | Linux | Software | Android | Check Download Exists
stat:
path: "{{ android_download_file }}"
register: android_download_stat
when: coding == true
## Packages ##
# https://docs.flutter.dev/get-started/install/linux/android
- name: Workstation | Linux | Software | Android | Dependencies [Install]
package:
name:
- default-jdk
- libc6
- libncurses5
- libstdc++6
- lib32z1
- libbz2-1.0
state: present
when: coding == true
- name: Workstation | Linux | Software | Android | Dependencies [Remove]
package:
name:
- sdkmanager
state: absent
when: coding == true
## Install SDK ##
- name: Workstation | Linux | Software | Android | SDK
block:
- name: Workstation | Linux | Software | Android | Download Commandline Tools
get_url:
url: "{{ android_url }}"
dest: "{{ android_download_file }}"
owner: "{{ user }}"
group: "{{ user }}"
mode: '0664'
when: not android_download_stat.stat.exists
- name: Workstation | Linux | Software | Android | Create Folder
file:
path: "{{ android_sdk_cmdline_temp }}"
state: directory
owner: "{{ user }}"
group: "{{ user }}"
mode: '0755'
- name: Workstation | Linux | Software | Android | Extract Tools
unarchive:
src: "{{ android_download_file }}"
dest: "{{ android_sdk_cmdline_temp }}"
owner: "{{ user }}"
group: "{{ user }}"
become_user: "{{ user }}"
when: coding == true and not android_sdkmanager_temp_stat.stat.exists
- name: Workstation | Linux | Software | Android | Delete Archive
file:
path: "{{ android_download_file }}"
state: absent
## Configure Modules ##
# This can only be run once, otherwise cmdline-tools creates latest-* folders.
- name: Workstation | Linux | Software | Android | Install Consistent Modules
shell: "yes | {{ android_sdkmanager_temp }} --install '{{ item }}' --sdk_root={{ android_sdk_location }}"
loop:
# Current
- cmdline-tools;latest
- platform-tools
- emulator
become_user: "{{ user }}"
when: coding == true and not android_sdkmanager_final_stat.stat.exists
# Regarding images to download; the `default` is the smallest, then `playstore`.
# The `google_apis` images are significantly larger than the `playstore` option.
#
# This script was used to download and test the sizes:
#
### #!/bin/bash
###
### cd /home/ling/SDKs/Android/Sdk/cmdline-tools/latest/bin
###
### # Actually to be used
### echo "35 Play Store"
### ./sdkmanager --install "system-images;android-35;google_apis_playstore;x86_64"
### echo "36 Play Store"
### ./sdkmanager --install "system-images;android-36;google_apis_playstore;x86_64"
###
### # FORTESTING file size
### echo "35 AOSP"
### ./sdkmanager --install "system-images;android-35;default;x86_64"
### echo "36 APIs Only"
### ./sdkmanager --install "system-images;android-36;google_apis;x86_64"
### echo "35 APIs Only"
### ./sdkmanager --install "system-images;android-35;google_apis;x86_64"
###
### exit 0
#
# These were the results:
#
### ~/SDKs/Android/Sdk/system-images]$ du -had2 | sort -h
### 1.7G ./android-35/default
### 2.2G ./android-35/google_apis_playstore
### 2.3G ./android-36/google_apis_playstore
### 3.5G ./android-35/google_apis
### 4.3G ./android-36/google_apis
### 6.6G ./android-36
### 7.3G ./android-35
### 14G .
# These are safe to run multiple times, and uses the new `latest` version.
- name: Workstation | Linux | Software | Android | Install Modules
shell: "yes | {{ android_sdkmanager_final }} --install '{{ item }}' --sdk_root={{ android_sdk_location }}"
loop:
### 36 ###
- build-tools;36.0.0
- platforms;android-36
- sources;android-36
# Images
#- system-images;android-35;default;x86_64 # TODO: Switch once it exists.
- system-images;android-36;google_apis_playstore;x86_64
### 35 ###
- platforms;android-35
- sources;android-35
# Images
- system-images;android-35;default;x86_64
### 16 ###
- platforms;android-16
- sources;android-16
# Images
- system-images;android-16;default;x86
become_user: "{{ user }}"
when: coding == true
# Remove any versions which used to be part of this script and no longer used.
- name: Workstation | Linux | Software | Android | Remove Modules
shell: "yes | {{ android_sdkmanager_final }} --uninstall '{{ item }}' --sdk_root={{ android_sdk_location }}"
loop:
### 36 ###
# Images
- system-images;android-36;google_apis;x86_64
### 35 ###
- build-tools;35.0.0
- build-tools;35.0.1
# Images
- system-images;android-35;aosp_atd;x86_64 # ATD = Automated Test Device
- system-images;android-35;google_apis;x86_64
- system-images;android-35;google_apis_playstore;x86_64
### 34 ###
- build-tools;34.0.0
- platforms;android-34
- sources;android-34
# Images
- system-images;android-34;google_apis;x86_64
- system-images;android-34;google_apis_playstore;x86_64
### 16 ###
# Images
- system-images;android-16;google_apis;x86
### 15 ###
- platforms;android-15
- sources;android-15
# Images
- system-images;android-15;default;x86 # Not working in Android AVDs
become_user: "{{ user }}"
when: coding == true
# Report the currently installed packges.
- name: Workstation | Linux | Software | Android | Report Modules
shell: "{{ android_sdkmanager_final }} --list_installed --sdk_root={{ android_sdk_location }} > {{ android_report_file }}"
become_user: "{{ user }}"
when: coding == true
## Flutter and Licenses ##
- name: Workstation | Linux | Software | Android | Inform Flutter
shell: "{{ flutter }} config --android-sdk={{ android_sdk_location }}"
become_user: "{{ user }}"
when: coding == true
- name: Workstation | Linux | Software | Android | Licenses Agreements [1/2]
shell: "yes | {{ android_sdkmanager_final }} --licenses --sdk_root={{ android_sdk_location }}"
become_user: "{{ user }}"
when: coding == true
- name: Workstation | Linux | Software | Android | License Agreements [2/2]
shell: "yes | {{ flutter }} doctor --android-licenses"
become_user: "{{ user }}"
when: coding == true
- name: Workstation | Linux | Software | Android | Refresh Flutter Doctor Report
shell: "{{ item }}"
loop: "{{ flutter_report_commands }}"
become_user: "{{ user }}"
when: coding == true
## Configure Environment ##
- name: Workstation | Linux | Software | Android | Modify PATH (.bashrc)
blockinfile:
path: "{{ item }}/.bashrc"
block: |
export PATH="$PATH:{{ android_bin_location }}:{{ android_sdk_cmdline_final }}"
marker: '# {mark} MANAGED BY ANSIBLE | Android'
state: present
create: yes
backup: yes
loop:
- "{{ user_root.home }}"
- "{{ user_user.home }}"
ignore_errors: yes
when: coding == true and user_root.home != "" and user_user.home != ""
- name: Workstation | Linux | Software | Android | Modify PATH (.zshrc)
blockinfile:
path: "{{ item }}/.zshrc"
block: |
export PATH="$PATH:{{ android_bin_location }}:{{ android_sdk_cmdline_final }}"
marker: '# {mark} MANAGED BY ANSIBLE | Android'
state: present
create: yes
backup: yes
loop:
- "{{ user_root.home }}"
- "{{ user_user.home }}"
ignore_errors: yes
when: coding == true and user_root.home != "" and user_user.home != ""
## Uninstall SDK ##
- name: Workstation | Linux | Software | Android | Remove SDK
file:
path: "{{ android_sdk_location }}"
state: absent
when: not coding == true
## User Tools ##
# Only needed from repo if not a development device,
# otherwise better versions are in the SDK.
- name: Workstation | Linux | Software | Android | System Tools [Install]
package:
name:
- fastboot
- adb
state: present
when: not coding == true
- name: Workstation | Linux | Software | Android | System Tools [Remove]
package:
name:
- fastboot
- adb
state: absent
when: coding == true