44

I use Android Studio 2.1.3. When I run an Android app I pick an AVD, where can I pass command line options such as -http-proxy? I don't even find a way in the run configuration.

6
  • I think this will answer your question: stackoverflow.com/questions/1570627/… If it doesn't, please clarify what you want to do. Commented Sep 8, 2016 at 17:37
  • 4
    I don't know how I could be more clear ;-) If I wanted to run the emulator in the command line I would do emulator -avd name -http-proxy localhost:8888 but I don't use the command line, I click on the run button in Android Studio so I want to set the options somewhere in the IDE. Commented Sep 8, 2016 at 17:44
  • You can start the AVD first with command line. Then, when you click play, you can select which device to use. You can select the running AVD you've started with your command line, this should work. I don't think it's possible to do it otherwise with the settings in the AVD itself. Commented Sep 8, 2016 at 17:52
  • I'd try at least this stackoverflow.com/a/32629260/2442831 Commented Sep 8, 2016 at 19:11
  • 1
    Ravenix, it takes forever to launch when I use the command line... ShadowGod apparently you are right: stackoverflow.com/questions/34644264/… Commented Sep 12, 2016 at 19:58

4 Answers 4

25

I found a hacky solution to add parameters to the Android Studio AVD.

Android Studio by default uses the binary $ANDROID_SDK/emulator/emulator. In my case the path in MacOS is /Users/martin/Library/Android/sdk/emulator/emulator. What I did is:

  1. Rename the binary to emulator-original

  2. Create a bash script with the name emulator that contains:

    /Users/<YOUR_USERNAME>/Library/Android/sdk/emulator/emulator-original <PARAMS> $@``` 
  3. Change the script permissions with chmod +x emulator

Now Android Studio runs my script instead of running the binary

Update: try Stef's solution first, it looks better than this hack

Sign up to request clarification or add additional context in comments.

3 Comments

Worked like a charm also for linux!
In my case I had to disable the audio of the emulator because it was stopping the audio channel of my Mac. So, in my case I had to add the parameters at the end like this: #!/bin/bash ~/Library/Android/sdk/emulator/emulator-original $@ -qemu -no-audio Thank you, @MartinCR!
nice hack. but proper solution would be setting the env variable as pointed out in Stef's answer.
11

You can set emulator start parameters in an environment variable studio.emu.params; they will be added to the command line when AS starts the emulator, see source code.

Tested on Windows with AS 4.1 and set studio.emu.params=-writable-system.

4 Comments

Great. It worked for me! A note: you should restart your android studio after changing the enviroment variable to take it effect.
I was breaking my head searching this. glad found this post. I added this to my windows environment variable and restarted the Android studio, and ran AVD inside android studio. It used the env variable to launch the emulator. now I'm able to do remount. thanks a lot!
Worked for me too, although I had to check the source code reference to work out that you need to separate arguments and their options using commas rather than spaces, e.g. set studio.emu.params=-gpu,angle_indirect is equivalent to command line emulator -gpu angle_indirect
This is not working for me, Android Studio wraps the value of the variable in quotes when passing it as a parameter. So it means the entire thing is treated as one token, so if I want to do -dns-server 1.1.1.1 it fails to start with an error message of unknown option: -dns-server 1.1.1.1. This is with Windows 10.
1

I'm also missing those settings.. Some kind of workaround is to go to wifi settings -> tap and hold wifi network -> modify network and there update proxy/dns settings

Comments

0

After scraping my head on failed attempts, for me the only solution was to run the emulator with an older Android version (9.0).

Not an issue since I anyway want to stay compatible with older devices.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.