2

I develop an app that communicates to an external database. I have recently started working from home. For development purposes, both the database and Android Studio are on the same workstation, but the access has to be done via URL, so when the app goes into production the only change is the address being accessed.

Back in the office, my company had a DNS to resolve local addresses for us, so my experience with Android Virtual Devices (AVDs) was seamless. But now that I'm at home I need to set the /etc/hosts file on the virtual machine (and the machine in question uses Googles API, not Google Play, otherwise this would never work).

Following the steps on this awesome thread allowed me to set this up with no problem via command line using the steps below (Linux system):

start emulator on tools folder with writable permissios

  1. tools/emulator -avd <avdname> -writable-system

use adb to remount the file system and push a prepared hosts file into place

  1. platform-tools/adb root
  2. platform-tools/adb remount
  3. platform-tools/adb push <local>/hosts /etc/hosts

This gets the hosts file where it needs to be, and through Android Studio I can confirm that the file has been edited through File Explorer, and from this point on, development is seamless again.

However, when I close and restart the same virtual machine, now using Android Studio's Device Mananger Play button, the hosts file resets to what it was previously on the AVD. Also, the file system is no longer writable. As a result, I always have to start the AVD via command line.

I wonder if there's a solution to either:

  • save the new hosts file permanently on that particular machine so when Android Studio starts it his way the configuration is already there; or
  • set the -writable-system flag to Android Studio's own play button command somehow, so the changes I made in the hosts file appear again.

I appreciate in advance any thoughts.

Jorge_Freitas
  • 175
  • 1
  • 12
  • To add some context from https://issuetracker.google.com/issues/135857816#comment8: "If you save a snapshot with [the `-writable-system`] flag, then boot the emulator without the flag, it would not be able to load the snapshot.". – Jean-Baptiste Rudant Dec 05 '22 at 21:42

1 Answers1

1

You can set the studio.emu.params environment variable to -writable-system.

Something like set studio.emu.params=-writable-system on Windows, or launchctl setenv studio.emu.params -writable-system on MacOS.

Related: https://stackoverflow.com/a/64696876/2924547