I need to get the android emulator to use an auto-config proxy script.
I already know the basics of having android emulator utilize a proxy, one must either submit the http-proxy argument when starting the emulator program, or have the http_proxy environmental variable set on the system. (See here http://developer.android.com/tools/help/emulator.html)
However, my company uses an auto configuration script for its proxy, like this:
http://autoproxy.company.org/proxy/west.pac which turns out to be some java script like functions, actually.
So, I need the android emulator to be able to utalize this automatic configuration script. Now, I have tried a few things, such as:
set HTTP_PROXY=http://autoproxy.company.org/proxy/west.pac
and I also tried adding it as the last parameter too.
start /b emulator-x86.exe -netdelay none -netspeed full -avd Nexus_5_API_22_x86 -no-audio -http-proxy %HTTPS_PROXY%
The above gave me the following error:
emulator: http_proxy format unsupported, try 'proxy:port' or username:password#proxy:port'
I can't find much detail on this on Google. Everyone seems to be able to use the tradition proxy means of user:pass#proxy:port but this simply doesn't work. In fact, it ends up getting my windows account locked out!
Related
So I have set up charles proxy to monitor traffic that goes out of the android emulator.
Now when I open a website it in the Android browser For eg:- google.com I see google.com in charles proxy.
But when I open an app(say instagram app) in the emulator and if the app makes some network calls , I see ip addresses on charles proxy and not domain names.
Because of which the app gives me an error of something went wrong etc.
Can anyone tell me how to change the dns configs of the android emulator so that it sends hostnames instead of IP addresses?
Or any other solution to this problem.
Thanks
you can configure a proxy from the command line with the -http-proxy option when starting the emulator. In this case, you specify proxy information in in one of these formats:
http://<machineName>:<port>
or
http://<username>:<password>#<machineName>:<port>
The -http-proxy option forces the emulator to use the specified HTTP/HTTPS proxy for all outgoing TCP connections. Redirection for UDP is not currently supported.
Alternatively, you can define the environment variable http_proxy to the value you want to use for . In this case, you do not need to specify a value for in the -http-proxy command — the emulator checks the value of the http_proxy environment variable at startup and uses its value automatically, if defined.
You can use the -debug-proxy option to diagnose proxy connection problems.
You can get further detail about this topic here:
https://developer.android.com/studio/run/emulator-networking.html
There's no way to change the dns configs of the android emulator that can get hostnames instead of IP addresses, the only option to use proxy is explain on other SO threads here.
I am sure the packets are coming from instagram and/or maybe they use some firewall for security purpose.
It is not possible with emulator but you can use GENYMOTION for that. Genymotion is very good tool to use online emulator.
You can set proxy in setting->network.
try that .hope this will help you.
For Linux User
We can't able to use emulator started from android studio
We have to start emulator from terminal using this 2 commands
First Move to android sdk tools dir
$ cd /home/..../Android/Sdk/tools
Second start your emulator using this cmd
./emulator -avd Emulator_name -http-proxy http://Ur ip address:port/
Emulator_name : open AVD Manager second column you will get Emulator names, next you have to replace spaces in between name with underscore
like Nexus 5 API 22 --> Nexus_5_API_22
Eg: $ ./emulator -avd Nexus_5_API_22 -http-proxy http://12.1.0.222:8888/
Inside your emulator - go to settings ->network&internet ->mobileNetwork ->AccessPointNames. and then choose your network for editing it and put the IP and port of the Charles's computer.
Remember to open the emulator with poxy.
emulator with proxy
You can use 'ping' command to get the IP address.
I built the Android AOSP tree for the mako device successfully on my Ubuntu 14.04 LTS desktop with the '. build/envset.sh', 'lunch mako-userdebug', and 'make -j4' series of commands. I tried to run it in the emulator by following the Google-provided instructions (i.e. typing the 'emulator' command in a terminal right after the build is complete) but it does not work. The emulator starts up but is stuck on a black screen. I noticed the following warning/errors while the emulator starts up:
emulator: control console listening on port 5554, ADB on port 5555
emulator: can't connect to ADB server: Transport endpoint is not connected (errno = 107)
Any help in resolving this error is greatly appreciated.
Phil,
To make an image for the emulator, you will need to make one of the generic images. e.g. lunch aosp_arm-eng (you can also us userdebug, etc). It may not show up in the lunch menu, but it should be available nonetheless. The emulator was made strictly to test the changes made in the framework and to the default system properties (those that are hardware independent). Building the arm version should fix your errors!
Best!
I am trying to decrease the ridiculous CPU usage of my Android emulator.
Thanks to this answer I found out that the CPU usage can be greatly decreased by disabling audio.
Solutions
I found out there are three ways to run the emulator without audio.
As a command line flag:
$ emulator -avd <name> -noaudio
By editing ~/.android/<name>.avd/config.ini and replacing this line:
hw.audioInput=yes
with these two:
hw.audioInput=no
hw.audioOutput=no
Instead of using the graphical AVD manager, use the following command to create an emulator:
$ android create avd -n <name> -t <target>
Cons
All of these methods have downsides though.
Requires to pass the -noaudio flag each time. This means it can't be run from AVD manager.
config.ini is reset each time an edit is made using AVD manager.
Requires to explicitly set every property of the device instead of just being able to use a preset configuration.
Attempted (failed) solution
I decided it might help to just clone an existing device and disable the audio there.
However¸ this just created ~/.android/devices.xml and I couldn't fine any reference how to disable audio by default nor any ini files containing hardware definitions.
Question
Is it possible to create a predefined hardware configuration that has sound disabled by default? If so, how?
need to run emulator with proxy settings , I am using the following command in command prompt to start emulator
emulator -avd AVD_for_3_7_WVGA_Nexus_One -http-proxy http://username:password#IP:Port
Without http-proxy switch it is working fine , where as using the http-proxy following error occured :
FATAL:.//android/base/sockets/SocketWaiter.cpp:89:Check failed: isValidFd(fd). fd 1404 max1024
I'm experiencing the exact same issue.
Luckily there is a workaround and I can say it's working (at least in my case): adding the -no-audio parameter to the command:
emulator -avd <device_name> -no-audio -http-proxy http://<username:password#>IP:Port
edit: even if it's working for you, please star the bug to get it fixed!
For some reason Android Emulator doesn't like IP address as the proxy. If you are using Fiddler use localhost:8888:
emulator.exe -avd Nexus_5_API_21_x86 -no-audio -http-proxy localhost:8888
Don't forget -no-audio parameter too.
Adding "-http-proxy none" (without quotes) in Run configuration also fixes this issue as shown in image attached. Please note this is one way of fixing this issue. Your app may not be able to connect to internet via proxy later on.
All solutions above was unable to fix my case. For me proxy settings was required, so disabling a proxy parameter does not fit to me. The only solution that helps me is to disable "Use Host GPU" option in the emulator options. Adding "-no-audio" parameter is also required.
And it works! Slowly, but works.
It still doesn't work. Please star this bug report so we can get it fixed - I already suggested to modify FD_SETSIZE from winsock.h to higer value e.g. 2048 as it doesn't change windows socket implementation as per microsoft's documentation:
// Default FD_SETSIZE is 64 which is not enough for us.
# define FD_SETSIZE 1024
https://code.google.com/p/android/issues/detail?id=102361
This problem is really frustrating. It would be nice if fixed targeting real root because most of the configurations are behind proxy now-a-days.
I observed while researching on this problem for last couple of weeks that emulator is not stable when it comes to http-proxy.
I installed android-studio-bundle-141.2422023-windows on one of the other m/c on that although proxy settings worked nice for http sites but failed for https sites.
On my m/c it didn't work. I tried with all the options listed online like -no-audio or setting from APN(emulator setting), or various versions of using -http-proxy. But none is working for me.
This is still a bug in android emulator refer link - https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=102361
Problem was fixed on latest Android SDK Tools (at the time of writing is in preview). You need version 25+ in order to get the new emulator which doesn't have this problem anymore.
For automated testing (using Hudson) I have a script that generates a bunch of emulators for many combinations of Android OS version, screen resolution, screen density and language.
This works fine, except for the language part.
I need to find a way to change the Android system locale automatically. Here's some approaches I can think of, in order of preference:
Extracting/editing/repacking a QEMU image directly before starting the emulator
Running some sort of system-locale-changing APK on the emulator after startup
Changing the locale settings on the emulator filesystem after startup
Changing the locale settings in some SQLite DB on the emulator after startup
Running a key sequence (via the emulator's telnet interface) that would open the settings app and change the locale
Manually starting the emulator for each platform version, changing the locale by hand in the settings, saving it and archiving the images for later deployment
Any ideas whether this can be done, either via the above methods or otherwise?
Do you know where locale settings are persisted to/read from by the system?
Solution:
Thanks to dtmilano's info about the relevant properties, and some further investigation on my part, I came up with a solution even better and simpler than all the ideas above!
I have updated his answer below with the details.
Personally I think the simplest way is to start the emulator, probably a clean instance unless you are running integration tests that depends on other applications and then change locale using adb:
$ adb shell '
setprop persist.sys.language en;
setprop persist.sys.country GB;
stop;
sleep 5;
start'
or whatever locale you want to set.
To verify that your change was successful just use
$ adb shell 'getprop persist.sys.language'
You may also want to run emulators on know ports, check my answer in this thread.
Note that you can also set system properties directly when starting the emulator:
emulator -avd my_avd -prop persist.sys.language=en -prop persist.sys.country=GB
This way, you can create a plain old emulator of any type then start it up immediately using the locale of your choice, without first having to make any modifications to the emulator images.
This locale will persist for future runs of the emulator, though of course you can always change it again at startup or during runtime.
Accepted answer doesn't work anymore. persist.sys.language and persist.sys.country are gone from emulator properties.
My solution is to use preinstalled on android emulator "Custom locale" application. Simply send intent with extra language parameter to it as below:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
More information here - prepare android emulator for UI test automation.
UPDATE: based on comment from Jonas Alves the following command works on API 28+:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "en_US" com.android.customlocale2
Seems that Android emulator now supports setting the locale when starting it:
emulator -avd <avd-name> -change-locale fr-CA
Source - https://androidstudio.googleblog.com/2019/09/emulator-29112-stable.html