Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Android emulator DNS server from Android Studio

Essentially my issue is that when I run emulator -verbose -avd Nexus_5X_API_19 in the command line the emulator starts up with the argument -dns-server = "w,x,y,z" where w,x,y,z are 4 ip addresses for DNS servers. When I run ipconfig /all I only see x,y,z listed as my valid DNS servers in Windows. Because of this odd first DNS server, I am unable to access the internet within the emulator. When I run the emulator with emulator -verbose -avd Nexus_5X_API_19 -dns-server "x,y,z" everything works fine.

But now I want to be able to run my app from within Android Studio 2.2.3 with the corrected DNS servers. So does anyone know how to specify the emulator command line arguments within Android Studio (similar to this answer for the older Eclipse based version: https://stackoverflow.com/a/4736518/1088659), or how to set the default DNS for the emulator to start with?

like image 422
justarandomuser12345 Avatar asked Mar 16 '17 16:03

justarandomuser12345


People also ask

Where is emulator settings in Android Studio?

Setting Up the Android Emulator Select Tools > SDK Manager. Then, from the settings window, choose Android Emulator. Click Apply, and Android Studio will download the emulator for you.

How do I enable Internet on Android Emulator?

Go to your Android\Sdk\emulator folder and open command prompt. Type emulator -list-avds to see available emulator names. Type emulator -avd name-of-your-device -netdelay none -netspeed full -dns-server 8.8. 8.8 command and press enter.

How can I use Android Studio as a mobile emulator?

Emulator for native development with Android StudioIn the Android Studio toolbar, select your app from the run configurations drop-down menu. From the target device drop-down menu, select the device that you want to run your app on. Select Run ▷. This will launch the Android Emulator.


2 Answers

Unfortunately, as of 3.0.1, this isn't possible. They removed adding additional arguments for emulators launched from Android Studio. Until they add it back in, starting the emulator from the command line (as you showed) is the only option.

You can track this issue here: https://issuetracker.google.com/issues/37071385

like image 190
jcady Avatar answered Oct 12 '22 18:10

jcady


If you are on MacOS or Linux, you could rename the Android Emulator executable to something else (say emulator-binary) and create a script with the actual emulator name (emulator) in its place, that calls the executable with the -dns-server parameter.

Here are the steps required:

  1. Find the path where the Android SDK is located in your system. This answer will help you find it.

  2. cd <your-SDK-path>/emulator.

  3. Rename the original executable: mv emulator emulator-binary.

  4. Finally, create an emulator shell script named emulator with the following contents:

<your-SDK-path>/emulator-binary -dns-server "8.8.8.8,8.8.4.4" $@

like image 26
m_katsifarakis Avatar answered Oct 12 '22 20:10

m_katsifarakis