Skip to content

Instantly share code, notes, and snippets.

@traumverloren
Last active March 29, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save traumverloren/ef1e31d80b306f786ea74c5a86d8e4f3 to your computer and use it in GitHub Desktop.
Save traumverloren/ef1e31d80b306f786ea74c5a86d8e4f3 to your computer and use it in GitHub Desktop.
Install Android Studio Emulator for use with aliased domain

How to change a hosts-file on Android Studio emulated phone

Pre-steps:

  1. Install Android Studio
  2. Add android to PATH in your .bash_profile or .zshrc file:
  • export ANDROID_SDK=$HOME/Library/Android/sdk
  • export PATH=$ANDROID_SDK/emulator:$ANDROID_SDK/tools:$PATH
  • export PATH=${PATH}:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools

Please follow these steps closely:

  1. In AVD manager: Create a test device without the (Google API) Play Services
  • Choose a new device in "Select Hardware". Click next.
  • In "System Image" click on "x86 Images". Choose a version without "(Google APIs)" which you probably have to download on the left.
  1. In your terminal window type: emulator -writable-system -avd <your-device-name>
  • The emulator should now open a phone.
  1. Open another terminal window(!). Then type and hit enter: adb root
  • It should say: "restarting adbd as root" or "running as root"
  1. Type and hit enter: adb remount
  • It should say: "remount succeeded"
  1. Type and hit enter: adb push Desktop/hosts /system/etc/
  • (Or use any path where your hosts file is.)
  1. Validate by going to the shell and looking at the hosts file:
  • Type and hit enter: adb shell
  • Your are now in the shell.
  • Type and hit enter: cat system/etc/hosts
  • You should now see the new hosts file.
  1. Shut down the emulated phone.
  2. Launch the phone again with: emulator -writable-system -avd <your-device-name>
  3. Google something like "cats" to see if you're connected to the internet.
  4. Type into the browser bar: https://dev.blahblah.com
  5. Follow the sign in flow.

To shut down emulator:

adb -s emulator-5554 emu kill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment