Android emulator doesn't use Windows host file? - android

m3 http://img245.imageshack.us/img245/461/65254534.jpg
Chrome using the windows' HOST file:
m1 http://img266.imageshack.us/img266/9380/59750633.jpg
Android emulator:
m2 http://img821.imageshack.us/img821/7363/19470766.jpg
edit
"On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually means that the emulator ignores the content of your "hosts" file (/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS on Windows)."
how can I use static IPs in the emulator?

I got this article, it explains how to edit the hosts file. I don't know if it works yet, bit it might help.
BROKEN (Feb 2015) - http://www.bradcurtis.com/2011/02/13/hosts-file-google-android-emulator/ (Leaving it in case it recovers)
If I'm not wrong, they moved the link here, I'm not sure if it's the same article, I haven't touched this since may 2012.
http://www.bradcurtis.com/hosts-files-and-the-google-android-emulator/ (Mirror Link https://web.archive.org/web/20180615121728/http://www.bradcurtis.com/hosts-files-and-the-google-android-emulator/)
EDIT: Adds a new link that works and talks about the ame issue (Not sure if it's the same article.

FWIW, it's not possible to change the phone's own /etc/hosts file within the emulator - it's on a read-only file system.
Personally, I'd run a local resolving server on your PC, point your Windows O/S at that, and then override the entries properly.
Unbound will do the job, and has a nice feature to allow you to insert "local data" into your DNS results.

It is possible to update the Android phone's own hosts file with:
adb remount
adb push hosts /etc/system/hosts (most tutorials suggest this file)
adb push hosts /system/etc/hosts (some VM systems seem to prefer this file instead!, for me this worked)
if any issues like i kept randomly getting a 'read-only file system' error 90
% of the time I tried running above, then try running 'adb root' before above (didnt work for me through), or start the Android VM manually with your android sdk's emulator.exe:
emulator.exe -avd Nexus_6_API_23 -partition-size 512
(some peeps recommended making partition size manually so can write to the VM easier?, eh seemed to work better but still got random read-only errors still).
An Android VM created with GenyMotion seemed much stabler and never get 'read only file system' issues with their VMs when i tried pushing the hosts file.
If the website you want to look at is hosted on your host machine, then you can point to it via a special IP android VMs recognize as the host machine via the hosts file:
10.0.2.2 test-drupal8.localhost
or if using Bridged Networking instead of NAT (pretend your windows host machine is 172.16.6.50 where your website is hosted and Android VM is 172.16.6.51), then can use windows ip directly:
172.16.6.50 test-drupal8.localhost
Note: make sure Windows Firewall/antivirus/firewalls are off if testing as they were blocking my urls until i turned them off.

Related

Mount MTP device on windows

I am attempting to mount an android device on a machine running Windows 10 for the purpose of accessing files via a Java application. I am aware that the consensus is one should use a WebDav or FTP server, but I would like to avoid this if possible. I have spent many weeks researching this and have finally decided to reach out to the brilliant minds of stack overflow.
To mount the MTP device we need a file system library similar to fuse for Unix. For windows the two obvious choices are:
dokany
winfsp
As far as I understand there are two main APIs/libraries to access MTP devices:
libmtp
WPD
I have managed to compile libmtp for windows using msys2/Mingw64.
The way I see it I should use an application like mtpmount or try to port a linux application like simple-mtpfs using a file-system library like dokany instead of fuse.
However, when I try to use mtp-mount (which uses the WPD API) it doesn't list any devices, and when I test libMTP using the provided examples I get errors like this:
libusb_open() failed!: No error
libmtp version: 1.1.18
Listing raw device(s)
Device 0 (VID=04e8 and PID=6860) is a Samsung Galaxy models (MTP).
Found 1 device(s):
Samsung: Galaxy models (MTP) (04e8:6860) # bus 1, dev 10
Attempting to connect device(s)
OK.
LIBMTP PANIC: Unable to initialize device
Unable to open raw device 0
I don't know how to proceed. Any help would be greatly appreciated.
Update
I got libmtp working using libusbk-dev-kit. Specifically, I used the libusbK-inf-wizard, to create drivers for my device. I tested the libusbk driver and the WinUSB driver and found they both solve my problem.
Also, I build mtpmount from sources and found it to work as well.
I found your question while looking for something very similar: how to talk with MTP (a Garmin Alpha 200i handheld GPS unit - not a phone) using Python 3 on Windows 10.
Glad to see you found a solution! I found a partial solution for my issue using your leads (Specifically, mtpmount), and am wondering if it provides another alternate solution for your issue.
I'm also wondering if you've discovered any more about mtpmount since you found your solution.
Based on your lead, I went to the mtpmount link. I was able to get a full solution for the windows command line by 1) downloading and running the latest .msi for dokany, making sure to select all the components for installation, then 2) downloading the latest .exe (it's not an installer - it's the actual mtpmount executable) for mtpmount. That's about as smooth of an installation process as one could hope for in this realm! Hats off to the developers on both of those projects!
The only differences vs the mtpmount docs I found were that 1) the executable name in the docs didn't exactly match the executable name from the downloads - certainly not a big deal, and 2) the pound sign has to be in double quotes - at least that was the case in powershell, and 3) a good thing: you can specify the drive letter in the same ID# syntax:
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe list available
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.
Available Connections and Storage Media:
Connection Elements: Contains 1 storages that can be mounted
|-- Storage E: [ID #0]
Connection My Passport: Contains 1 storages that can be mounted
|-- Storage F: [ID #1]
Connection Alpha 200i: Contains 2 storages that can be mounted
|-- Storage Internal Storage [ID #3]
|-- Storage Memory Card [ID #4]
Use mount command to make one of them a windows removable drive
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe mount "#3" h:
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.
Drive H:\ is now Alpha 200i\Internal Storage. Don't forget to unmount the drive (using unmount command) before disconnecting your device
PS C:\Users\caver\Downloads>
Then you do your drive access work. Then you run this to dismount:
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe unmount "#3"
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.
Alpha 200i\Internal Storage has been unmounted successfully.
Syncing Alpha 200i. DO NOT UNPLUG THIS DEVICE YET!
the terminal pauses for about 5 seconds here
Cache OK
All content synced to Alpha 200i. You may now unplug this device.
PS C:\Users\caver\Downloads>
My questions about this:
does dokany affect the rest of your file system access, by running all file system operations through its proxy for all drives? If so, does that slow things down or add another possible route for file system corruption in the event of an undiscovered bug in dokany or such?
we work with the Garmin GPS units in an environment where unplug timing can't really be reliably controlled. In other words, we really need to be able to unplug immediately after the transfer is done, without waiting for the pregnant pause during the unmount process. What's the word on hot-unplugging of a MTP device that's mounted using mtpmount? Unplugging without running 'mtpmount unmount', and also, unplugging during the pregnant pause? Of those two options, seems like it would be safer to just not run unmount - you get the impression that the 5-second sync would be a really bad time to unplug... For USB Mass Storage Devices, I know it's always recommended to properly eject the device from Windows first, before physically unplugging, but we've never experienced a problem due to hot-unplugging of USB Mass Storage Mode Garmin GPSes.
have you made this all into a turnkey installer solution, i.e. one overall installer that installs dokany then installs mtpmount then also installs the rest of your application? I am not familiar with installers like Nullsoft or such and I definitely plan to RTFM there, but just wondering if you've encountered any specific hiccups on these lines.
Thanks and congrats on getting it working!

How to use android device as host to pull logs from another android device?

Usually we use windows/linux machines to pull logcat info from an android device.
Is it possible to use android tablet/phone to act as host and get the logs from another android phone connected to it?
This is possible. The host Android device needs to be defined as a USB host. Then, once a connection is established, all of the same commands can be run, assuming that ADB is installed on the host device.
See here for more discussion on USB Host Mode support and compatible cables: https://android.stackexchange.com/questions/36887/how-can-i-determine-if-my-device-has-usb-host-mode-otg-support
It is useful to have a terminal program, such as Terminal IDE to issue commands from, and using busybox to provide additional commands would also be beneficial.
ADB comes as part of the AOSP source, so it a device is based off AOSP, then it will possibly include ADB. ADB source is located in /system/core/adb in the AOSP source tree.
Here is an example of a session where a Nitrogen6X (host) running a custom AOSP is used to connect to a Galaxy S3 cellphone (client). Note the use of Busybox and ADB, both of which are installed on the host. Busybox also happens to be installed on the client, but this is not necessary:
Thus in order to pull logs, just use regular ADB commands (e.g. to copy files), or run logcat, as indicated below:

Using System Hosts file for Android Emulators

I having problem in using my system hosts file details in Android Emulators.
I have my website (www.example.com) deployed in Webserver.
I am trying to access those website in Emulator from my desktop.
My desktop has a hosts file with the entry of
10.xx.xx.xx www.example.com
I am trying to access the www.example.com from the android emulator - browser and it is not working.
I took a reference from the below website, but most of the website says how to use the hosts file if the website is deployed in the same server.
http://sadhanasiblog.blogspot.in/2012/07/local-environment-setup-for-android.html
Please let me know if anyone has answers. Thanks in Advance.
-Senthil
With latest Android studio and tools. You can now use follow this instructions. You only need to run this once per emulator.
Start the emulator with following command. This command is located under your [sdk folder]/tools directory
emulator #[emulator name] -writable-system
Open another command prompt and then switch your directory to [sdk folder]/platform-tools and run following commands
adb root
adb remount
adb shell
echo '10.0.2.2 [localserver dns name]'>>/etc/hosts -- example echo '10.0.2.2 xxxx.com'>>/etc/hosts
One important thing to check is, if you create your HOSTS file on Windows or MacOS machine, that the HOSTS file contains linux line endings ('\n', LF, #10, #0x0A). Android ignores the HOSTS file if it contains Windows' 2-char line endings ('\r\n', CRLF, #13#10, #0x0D0A) or MacOS-style line endings ('\r', CR, #13, #0x0D).
Except for letters/numbers/dots (used for IP and host names) the file should contain only characters 0x20 (space), 0x09 (tab) and 0x0A (new line).
To acces to your localhost the IP is
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
From Android docs:
At startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list and sets up aliases to them on the emulated addresses 10.0.2.3, 10.0.2.4, 10.0.2.5 and 10.0.2.6 as needed.
On Linux and OS X, the emulator obtains the DNS server addresses by parsing the file /etc/resolv.conf. On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually means that the emulator ignores the content of your "hosts" file (/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS on Windows).
When starting the emulator at the command line, you can also use the -dns-server option to manually specify the addresses of DNS servers to use, where is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter DNS resolution problems in the emulated network (for example, an "Unknown Host error" message that appears when using the web browser).
At your console use:
emulator -avd <you_avd_name> -dns-server <serverList>
I used when I had to connect to a VirtualBox with a linux distro on the same PC and it worked from the emulator webview http://10.0.2.3/servlet-name
Reference: Emulator Networking

Could not open Selected VM debug port (8700)

I am trying to debug the android source using Eclipse by following the instructions found at:
http://source.android.com/using-eclipse
I have downloaded the source, and gotten it to build. I follow the directions in the link above and everything is fine until I run the ddms command. At this point, if Eclipse is running I get the error 'Could not open Selected VM debug port (8700)'. If I close Eclipse, then ddms runs with no problem, and I can the the processes on the emulator. However, if I now open Eclipse, I get the same error.
In any case, no matter what I do, if I attempt to remote debug, it always fails with 'Failed to connect to remote VM'.
Any ideas?
Thanks
It looks like you have two problems:
You are trying to run DDMS twice. You do not need to run the free standing version of DDMS since there is version of it integrated in Eclipse as part of the Android plug-in. If you change to the DDMS perspective in Eclipse, I'm sure you will find that all the same features are available.
You have not told DDMS which VM you want to debug at localhost:8700. Before you attempt to establish your remote debug connection, you must go to the DDMS perspective and click on the system_process (or whatever process you want to debug).
The Windows Host file that is messed up is at C:\WINDOWS\system32\drivers\etc, and it should contain this line:
127.0.0.1 localhost
If that doesn't work, then try making the following changes in Eclipse.
Under Window -> Preferences -> Android -> DDMS:
Set Base local debugger port to "8601"
Check the box that says "Use ADBHOST" and the value should be 127.0.0.1
I solved it by ending the process "adb.exe" through Task Manager and then reloading the SDK through Windows->Preference..I am running Eclipse Indigo on Win 7 64-bit.
I was having that problem too (Windows 7), even though my /Windows/system32/drivers/etc/hosts file already had 127.0.0.1 localhost in it.
I tried changing the ADBHOST info & port in the eclipse Preferences, but that didn't do anything.
netstat -b shows '127.0.0.1' as the source address for adb and the emulator, but always lists my machine host name as the 'foreign address.' On a hunch, I tried debugging with my machine not connected to any network (no WiFi, nothing plugged in)... and it worked! (DDMS was able to connect to the VM on the emulated device and I was able to debug just fine.)
I think that messages sent by DDMS &/or adb are not staying on my local machine (they're getting sent to my local router). (It's just a guess; I don't know how to conclusively test that.) IOW, loopback wasn't working as it should.
Since I already had 127.0.0.1 in my localhosts, I added the local subnet address of my machine into my hosts file, guessing that DDMS/adb might be using that address (vs. 127.0.0.1). That seemed to solve the problem for me.
So now my hosts file has these lines:
127.0.0.1 localhost
::1 localhost
192.168.1.102 localhost
(The local IPv4 address for my machine is 192.168.1.102 . You can check yours with the ipconfig command.)
(I came across some webpages that how to set up a virtual network adapater for Windows that handles loopback, e.g. Setting up a Microsoft Loopback Adapater (from Oracle Distilled), but haven't had time to take that in and see if that's a viable solution to all of this, too.)
I solved it by opening the windows Task manager and closing the process "adb.exe". Then close eclipse and reopen it. It will start properly without any error.
This is for reference. But I guess this might match your case.
Port 8700 is very special port for ddms; there's no way to change the port.
Port 8700 is used for aggregating the packet from every Dalvik VM.
There will be two cases;
case 1) If you set "Base local debugger port"(in Eclipse ddms preference dialog) to 8700, then you'll see error - "Can't bind to local 8700 for debugger", everytime ddms initiated. But no problem, because if ddms couldn't bind 8700 to the first VM, then will be connected to 8701, and then 8702 and so on.
case 2) Even if you set "Base local debugger port"(in Eclipse ddms preference dialog) to 8600, you may see error - "Can't bind to local 8700 for debugger", in some cases. Because, if your device have more than or equal to 100 dalvik VMs, port assigning to each VM starting from port 8600 may reach to 8700 port. But, no problem occurs same as in case 1).
So, if you really don't want to see the error, you have to set the "Base local debugger port"in Eclipse ddms preference dialog to 8701 or above.
Stand-alone ddms or android monitor uses different setting file from Eclipse, so it may not make this kind of problems.
~
Had the same problem, different port numbers in the console output (where I launch ddms) caught my attention
Then from the documentation, I learned that 8600 is the default base port number. Every new process uses the next available port (8601,8602,...). In addition, 8700 is the default active port number (indicating the currently selected process in the dbms)
Here are the steps to debugging Android source+applications
Run emulator
Run ddms
Open Eclipse (It may complain about being unable to connect to 8600. This is because, when Eclipse starts up and if you have Android plugin, it boots up ddms. Since we already have a ddms connected to the device, trying to connect for a second time won't work)
In the ddms, pick a thread you want to debug (when you highlight it, it will show you the ports that it is using as well as 8700 (e.g. "8649 / 8700"). This means you can use both ports to connect to this process
From eclipse, using the remote debugging configuration, connect to any process you wish (easiest is to highlight the process from within ddms and then connect to 8700)
This type problem occurs when you are using another VM with the same port number. As an example you are using Android SDk full bundle which you have downloaded from the android developer website. Now you want to use Eclipse and plugged in ADT, SDK. There is a high probability to happen this type of error. It happened to me. To overcome this difficulties you can do :
Window-Preferences-Android- Choose DDMS- Change base local debugger port(use 8601 instead of 8600).
It can work. Thanks
I done it by restarting my computer
Just for completeness: (on win 7/Vista) not only you have to make sure line
127.0.0.1 localhost
is present in
C:\WINDOWS\system32\drivers\etc
you also need to comment out all your other local virtual hosts resolving from 127.0.0.1. This is most probably the case if you're developing web stuff on the same machine and set it up earlier for different host names looping back to local.
I solved the problem by ONLY close android studio so the eclipse can get ddms
When I execute monitor in $ANDROID_HOME/tools/monitor on Ubuntu 16.04, it shows
Could not open Selected VM debug port (8700). Make sure you do not
have another instance of DDMS or of the eclipse plugin running. If
it's being used by something else, choose a new port number in the
preferences.
I tried to do the following:
Under Window -> Preferences -> Android -> DDMS:
Set Base local debugger port to "8601" Check the box that says "Use
ADBHOST" and the value should be 127.0.0.1
But it still pops up the dialog.
Then I did the following:
gongzelong#gongzelong:~$ netstat -apn |grep 8700
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:8700 0.0.0.0:* LISTEN 5044/java
gongzelong#gongzelong:~$ kill -9 5044
gongzelong#gongzelong:~$ monitor
By doing this, it solved my problem.
Do not know why, but it works for me.

Android SDK and AVD Manager, Stalls and/or never finishes

Recorded for posterity.
I saw only a few posts around the net and all suggest to use HTTP instead of HTTPS and there were several ways to do this. None of them discussed Windows only Linux. Well this did not work for me and I could not find any way to get the files downloaded to my Windows Vista 64 machine.
So after much work I manually downloaded them and got them to work. I did this by putting it on a machine that did work and reading the repository.xml file and downloading them.
https://dl-ssl.google.com/android/repository/google-apis-4_r02.zip
Unzipped it and moved the top directory into
android-sdk-windows/add-ons
and
https://dl-ssl.google.com/android/repository/android-1.6_r02-windows.zip
I then extracted them and renamed the top directory android-1.6 (it is at least one level below the unzipped directory) and moved it to
the platforms directory
Then rebooted my machine and it seems to work.
Hope this helps someone.
Julian
you need to disable auto tuning on your network adapter. i was going crazy trying to figure this out.
run this in an administrator command prompt (right click command prompt from the start menu, run as administrator)
netsh interface tcp set global autotuning=disabled
restart avd manager
On Mac OS X, the corresponding command for turning off auto tuning is:
sudo sysctl -w net.inet.tcp.rfc1323=0
This fixed the issue for me.
Source: Handling TCP Window Scaling

Categories

Resources