How to pass command line options to the emulator in Android Studio?
Asked Answered
I

3

41

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.

Inoculum answered 8/9, 2016 at 17:34 Comment(6)
I think this will answer your question: #1571127 If it doesn't, please clarify what you want to do.Loafer
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.Inoculum
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.Loafer
I'd try at least this https://mcmap.net/q/197062/-android-studio-emulator-parametersObligato
I did some research on this and someone correct if I'm wrong but I think you used to be able to do this easily in Android Studio but they removed the option. Why they removed it and how to do it now I'd like to know as well.Detachment
Ravenix, it takes forever to launch when I use the command line... ShadowGod apparently you are right: #34644764Inoculum
E
23

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

Espousal answered 15/8, 2018 at 12:24 Comment(3)
Worked like a charm also for linux!Expiration
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!Tound
nice hack. but proper solution would be setting the env variable as pointed out in Stef's answer.Buffington
C
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.

Cauley answered 5/11, 2020 at 12:6 Comment(3)
Great. It worked for me! A note: you should restart your android studio after changing the enviroment variable to take it effect.Ataman
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!Buffington
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_indirectTrinitrophenol
C
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

Calctufa answered 3/3, 2018 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.