Skip to content

Instantly share code, notes, and snippets.

@mrk-han
Last active September 20, 2022 23:52
Show Gist options
  • Save mrk-han/3697fc438e1f0f77d66caccd63708341 to your computer and use it in GitHub Desktop.
Save mrk-han/3697fc438e1f0f77d66caccd63708341 to your computer and use it in GitHub Desktop.
Setting up Linux Environment to run Espresso tests on Android x86 Emulator
# Android w/ x86 Emulator
## SETUP
sudo -S apt-get update && sudo apt-get upgrade -y
sudo -S apt-get install zip unzip wget git curl vim openjdk-8-jdk qemu-kvm -y
sudo -S adduser $USER kvm
mkdir -p Android/platforms
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d Android/
rm sdk-tools-linux-4333796.zip
curl -s https://get.sdkman.io | bash
source "/home/developer/.sdkman/bin/sdkman-init.sh"
sdk install kotlin
nano ~/.bashrc
// Put the following exports into your bashrc
export ANDROID_HOME=~/Android
export PATH=$PATH:~/Android/tools/bin
export PATH=$PATH:~/Android/emulator
export PATH=$PATH:~/Android/platform-tools
// xml bind issue https://stackoverflow.com/questions/47150410/failed-to-run-sdkmanager-list-android-sdk-with-java-9
export JVM_OPTS="-XX:+IgnoreUnrecognizedVMOptions"
export ANDROID_AVD_HOME=~/.android/avd
export ANDROID_SDK_ROOT=$ANDROID_HOME
source ~/.bashrc
// OPTION IF YOU DON'T EXPORT JVM_OPTS
vim $ANDROID_HOME/tools/bin/sdkmanager
### EDIT LINE ###
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions'
yes | sdkmanager --licenses
sdkmanager --install platform-tools
sdkmanager --install "system-images;android-28;google_apis;x86_64"
no | avdmanager create avd -k "system-images;android-28;google_apis;x86" -n TestDevice
sdkmanager "build-tools;28.0.2"
git clone https://github.com/googlesamples/android-sunflower.git
// REBOOT NOW
// CHECK FOR KVM SUPPORT
emulator @TestDevice -accel-check
// START EMULATOR
emulator @TestDevice -noaudio -no-boot-anim -netdelay none -port 5600 -accel on
// BuildAgent/conf/buildAgent.properties (Edit in Packer Script)
env.ANDROID_HOME=$SDKPATH
// List installed and available packages
sdkmanager --list
// List installed emulators
avdmanager list avd
// Get help about disk images relevant to app developers. It explains where the image files are located for an AVD created with the SDK tools. For example:
emulator -help-sdk-images
// Disable graphical window display on the emulator. This option is useful when running the emulator on servers that have no display. You'll still be able to access the emulator through adb or the console. For example:
emulator @Nexus_5X_API_23 -no-window
// DOCUMENTATION ---CAN IGNORE
-engine engine
Specify the emulator engine:
auto - Automatically select an engine (default).
classic - Use the older QEMU 1 engine.
qemu2 - Use the newer QEMU 2 engine.
For example:
$ emulator @Nexus_5X_API_23 -engine auto
// DEPRECATED
# Network/DNS Instructions #
sudo nano /etc/resolve.conf
>>> nameserver 8.8.8.8 # Google
nameserver 192.168.143.90 # Local DNS
sudo nano /etc/NetworkManager/NetworkManager.conf
// Insert dns=none under [main] # Disables DNS overwrite
sudo service NetworkManager restart # Restart network services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment