Skip to content

Instantly share code, notes, and snippets.

@guness
Forked from nhtua/00.install-android-sdk.sh
Last active May 10, 2022 13:19
Show Gist options
  • Save guness/5d2ec8aa81c843909dc88bc0f23bb136 to your computer and use it in GitHub Desktop.
Save guness/5d2ec8aa81c843909dc88bc0f23bb136 to your computer and use it in GitHub Desktop.
Run a Headless Android Device on Ubuntu server (no GUI)
#!/bin/bash -i
#using shebang with -i to enable interactive mode (auto load .bashrc)
set -e #stop immediately if any error happens
# Install Open SDK
apt update
apt install openjdk-11-jre-headless -y
java -version
# Install SDK Manager
# you can find this file at https://developer.android.com/studio/index.html#downloads - section command line only
cd ~ && wget https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip
ANDROID_SDK_ROOT=/opt/androidSdk
mkdir -p $ANDROID_SDK_ROOT/cmdline-tools
apt install unzip -y && unzip commandlinetools-linux-8092744_latest.zip -d $ANDROID_SDK_ROOT/cmdline-tools
mv $ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest
echo "export ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >> ~/.bashrc
echo 'export SDK=$ANDROID_SDK_ROOT' >> ~/.bashrc
echo 'export PATH=$SDK/emulator:$SDK/tools:$SDK/tools/bin:$SDK/platform-tools:$SDK/cmdline-tools/latest:$SDK/cmdline-tools/latest/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Accept Licenses
sdkmanager --update
yes | sdkmanager --licenses
# Install Android Image version 29
yes | sdkmanager "platform-tools" "platforms;android-29" "emulator"
yes | sdkmanager "system-images;android-29;google_apis;x86_64"
#yes | sdkmanager "system-images;android-29;google_apis;arm64-v8a"
# emulator -version
emulator -list-avds
# Fixing some issues
apt install libgl1-mesa-dev -y
echo "INSTALL ANDROID SDK DONE!"
echo "run 01.emulator-up.sh [new device name] to start emulator"
#!/bin/bash -i
#using shebang with -i to enable interactive mode (auto load .bashrc)
set -e #stop immediately if any error happens
REPO=~/.android/repositories.cfg
touch $REPO
echo ### User Sources for Android Repository >> $REPO
echo #Sun Mar 27 04:01:23 TRT 2022 >> $REPO
echo disp00=Aiden >> $REPO
echo count=1 >> $REPO
echo src00=https\://developer.volvocars.com/sdk/volvo-sys-img.xml >> $REPO
echo enabled00=true >> $REPO
yes | sdkmanager "system-images;android-29;ihu_emulator_volvo_car;x86_64"
#!/bin/bash -i
#using shebang with -i to enable interactive mode (auto load .bashrc)
#this script was inspired from https://docs.travis-ci.com/user/languages/android/
set -e #stop immediately if any error happens
avd_name=$1
if [[ -z "$avd_name" ]]; then
avd_name="volvo29"
fi
#check if emulator work well
# emulator -version
emulator -list-avds
# create virtual device, using Volvo Android 10 Q image (API Level 29)
echo no | avdmanager create avd -n $avd_name -k "system-images;android-29;ihu_emulator_volvo_car;x86_64"
# start the emulator
emulator -avd $avd_name -no-audio -no-window -no-accel -gpu swiftshader_indirect &
# wait for device
adb wait-for-device
# show connected virtual device
adb devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment