Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add -http-proxy to an android emulator launch from Android Studio 2.0

I have a local dev web server running on a machine sitting next to me.

I use a hosts file locally on my laptop to map an url to the machine and apparently the android emulator uses NAT and can't resolve the url.

I wanted to configure the emulator to use Charles Proxy for all Internet traffic so that it will go through my laptop and pick up my hosts file for name resolution.

The instructions here say I need to set -http-proxy.

How do I do that if I launch from Android Studio 2.0?

like image 993
Clintm Avatar asked Apr 22 '16 21:04

Clintm


People also ask

How do I transfer APK files to Android emulator?

We just need the APK file to install it in the Emulator. First of all, we still have to open the Emulator and after that drag, your APK file and drop it in the emulator anywhere and that's it it will simply install that app in the Emulator.

How do I transfer files to AVD?

Right click on that folder and select upload(or press Ctrl + Shift + O ). Select file you want to upload and it will upload file to desired location.


2 Answers

Run emulator from command line

emulator -avd <avd name> -http-proxy ip:port

emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888

Windows

%UserProfile%\AppData\Local\Android\sdk\tools\emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888

BTW I wasn't able to make a proxy work for me.

There other alternatives The best way to review Android HTTP connections:

  1. OKHtttp Logging Interceptor - logs in logcat, good for Retrofit

  2. Flipper https://fbflipper.com/ - nice UI and modern multiplatform approach

  3. Network Profiler - build into Android Studio, but I never made it work

  4. Stetho http://facebook.github.io/stetho - allows to display all android device/emulator requests/responses in Google chrome developer tools (deprecated but still works well)

like image 157
Igor Avatar answered Sep 20 '22 15:09

Igor


Open the Android emulator, go to mobile data settings, change the APN and insert there ip and port of your proxy.

From now on, all the data in/out of the emulator will go through your proxy.

Settings

Mobile Networks

Mobile Networks Settings

APNs

Proxy

like image 36
Sebastiano Tognacci Avatar answered Sep 22 '22 15:09

Sebastiano Tognacci