From df5cca3183be7b23879e0f9a7e949727d9f242b9 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Fri, 28 Mar 2025 09:43:21 +0100 Subject: [PATCH] add scritp --- android_env | 13 +++++++++++++ delate_emulators.sh | 8 ++++++++ emulator_first_boot.sh | 19 +++++++++++++++++++ install_android.sh | 14 ++++++++++++++ make_emulators.sh | 11 +++++++++++ start_emulators.sh | 25 +++++++++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 android_env create mode 100644 delate_emulators.sh create mode 100644 emulator_first_boot.sh create mode 100644 install_android.sh create mode 100644 make_emulators.sh create mode 100644 start_emulators.sh diff --git a/android_env b/android_env new file mode 100644 index 0000000..b1a4cfb --- /dev/null +++ b/android_env @@ -0,0 +1,13 @@ + +# Various Android directories, see for more information +export ANDROID_HOME="${HOME}/Android/Sdk" +export ANDROID_USER_HOME="${HOME}/.android" +export ANDROID_EMULATOR_HOME="${HOME}/.android" + +# Various directories containing android executables +export PATH="${ANDROID_HOME}/cmdline-tools/latest/bin:${PATH}" +export PATH="${ANDROID_HOME}/emulator:${PATH}" +export PATH="${ANDROID_HOME}/platform-tools:${PATH}" + +# If not set, adb will not see more than 16 emulators +export ADB_LOCAL_TRANSPORT_MAX_PORT=5885 diff --git a/delate_emulators.sh b/delate_emulators.sh new file mode 100644 index 0000000..fcbd794 --- /dev/null +++ b/delate_emulators.sh @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +BASENAME='root34' +MAX_EMU=10 + +for i in $(seq 1 "${MAX_EMU}"); do + avdmanager delete avd --name "${BASENAME}-${i}" +done diff --git a/emulator_first_boot.sh b/emulator_first_boot.sh new file mode 100644 index 0000000..57d3735 --- /dev/null +++ b/emulator_first_boot.sh @@ -0,0 +1,19 @@ +#!/usr/bin/bash + +# For some reason, the emulator will only boot in debug mode. Why? no fucking clue, ask google. +# Anyway, once booted a snapshot is created that will be used for the next times that will work +# without debug-init. +BASENAME='root34' +MAX_EMU=10 + +sdkmanager "${IMG}" + +# kill all emulators: +# for e in $(adb devices | grep emulator | sed 's/\t.*//'); do adb -s $e emu kill; done + +for i in $(seq 1 "${MAX_EMU}"); do + emulator -avd "${BASENAME}-${i}" -no-window -no-metrics -debug-init -logcat '*:v' & +done +#for i in $(seq 17 32); do +# emulator -avd "${BASENAME}-${i}" -no-window -no-metrics -debug-init -logcat '*:v' & +#done diff --git a/install_android.sh b/install_android.sh new file mode 100644 index 0000000..e039984 --- /dev/null +++ b/install_android.sh @@ -0,0 +1,14 @@ +#!/usr/bin/bash + +mkdir -p "${ANDROID_HOME}" \ + && mkdir -p "${ANDROID_USER_HOME}" \ + && mkdir /tmp/tmpinstall \ + && curl https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -o /tmp/tmpinstall/cmdlinetools.zip \ + && unzip /tmp/tmpinstall/cmdlinetools.zip -d /tmp/tmpinstall/ \ + && yes | /tmp/tmpinstall/cmdline-tools/bin/sdkmanager 'cmdline-tools;latest' --sdk_root=${ANDROID_HOME} \ + && rm -rf /tmp/tmpinstall \ + && yes | sdkmanager --licenses \ + && sdkmanager 'platform-tools' \ + && sdkmanager 'emulator' \ + && sdkmanager 'platforms;android-34' \ + && sdkmanager 'system-images;android-34;default;x86_64' diff --git a/make_emulators.sh b/make_emulators.sh new file mode 100644 index 0000000..6e9be93 --- /dev/null +++ b/make_emulators.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash + +IMG='system-images;android-34;default;x86_64' +BASENAME='root34' +MAX_EMU=10 + +sdkmanager "${IMG}" + +for i in $(seq 1 "${MAX_EMU}"); do + avdmanager create avd --name "${BASENAME}-${i}" --package "${IMG}" --sdcard 512M --device medium_phone +done diff --git a/start_emulators.sh b/start_emulators.sh new file mode 100644 index 0000000..5022887 --- /dev/null +++ b/start_emulators.sh @@ -0,0 +1,25 @@ +#!/usr/bin/bash + +BASENAME='root34' +MAX_EMU=10 +LOG_DIR=${1:-$(mktemp -d)} +START_PORT=5554 + +# kill all emulators: +# for e in $(adb devices | grep emulator | sed 's/\t.*//'); do adb -s $e emu kill; done +# and for the few that refuse to die after a few moments: +# pkill -f /home/android/Android/Sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64-headless + +echo "Emulator Log DIR: ${LOG_DIR}" + +for i in $(seq 1 "${MAX_EMU}"); do + CONSOLE_PORT=$((START_PORT++)) + ADB_PORT=$((START_PORT++)) + adb devices | grep -q "emulator-${CONSOLE_PORT}" + if [ $? -ne 0 ] + then + echo "start ${BASENAME}-${i} (emulator-${CONSOLE_PORT})" + emulator -avd "${BASENAME}-${i}" -no-window -no-metrics -ports "${CONSOLE_PORT},${ADB_PORT}" > "${LOG_DIR}/emulator-${CONSOLE_PORT}.stdout" 2> "${LOG_DIR}/emulator-${CONSOLE_PORT}.stderr" & + sleep 2 + fi +done