Debugging using a virtual machine like VMWare/Virt

2019-01-10 19:54发布

问题:

I am developing an Android application but fed-up of performance of My emulator I do have a Android PC version installed in both VM-ware and Virtual Box

Can I use it as emulator? If so, how? How can I connect ADB to a virtual machine running PC Android?

I saw in some forum to use this but my VMs android having no specific IP.

How to i connect it??

回答1:

Solution:

I would highly recommend to use Android x86 coz it many many times faster than Android emulator with Android x86 4.2 you can install and use any application with this and use "Google play" synch with your account as you do it with tablet

Working with latest Android X86 4.2 Jelly Bean and Virtual Box

I have found Different ways to connect with Internet and adb

Step: 1 Selection of Adapters

CASE 1: Only Internet {NAT Adapter}

The easiest solution is just use NAT adapter that will directly connect you to internet if host is connected to internet but you won't get the adb connection with this setup Here you will get Public ip so you can't connect to Host computer

Case 2: Only adb {Host Only Adapter}

The easiest solution is just use Host Only Adapter

Note: The default Host Only adapter may not work due to DHCP server settings either create new HostOnlyAdapter or run DHCP server for existing Adapter()

Case 3: For both adb and Internet {Bridge Adapter}

You will have to take care in this case.

If you are using LAN for internet connection you shall use Bridge Adapter with your Ethernet card it will give you local ip and Virtual Machine will connect to Internet using host machine

Alternatively if you are with Wifi just do the same by selecting the Wifi adapter

For other type of connection you shall go with the same way

Step: 2 Connection with adb

to check the ip Address just press Alt+F1 {for console Window} [To switch back to Graphics view press Alt+F7 ]

you will see the console window type netcfg

it will show the ip address

Now move on to you host run command prompt move to adb directory type

 adb connect {your ip address}

Example

adb connect 192.168.1.51

Note: if adb is not running or responding you can do following

adb kill-server

adb start-server 

you can check devices connected to adb

adb devices


回答2:

As per your edited question, if you want to connect it to ADB you need to check what the IP of the VM is: Assuming you use VMWare's player;

Hit ALT-F1 in the VM and use the ifconfig command to know the IP address given to your network device (usually eth0). You can then hit ALT-F7 to go back to the Android UI.

Then, in your host PC, execute the adb connect [ANDROID_X86_IP] to connect the SDK debugger to your Android x86 VM; for example: adb connect 192.168.1.100:5555.

You should then see the list of devices connected and then it will be enabled to use for debugging.

ADB is typically located on your computer in a subfolder to your user folder in: ~/Android/Sdk/platform-tools. It is recommended to add it to your path so you can access it using the terminal wherever. I personally use this in ~/.bash_profile:

#add Android platform-tools directory
PATH=~/android-sdks/platform-tools:$PATH
export PATH

In case ADB fails the first time, you can try adb kill-server ; adb start-server to reset ADB.

If you want to read further, check out the Android-x86 website. It also has a lot of disc images available for download.



回答3:

This is not a direct answer to your question, but did you see tricks to increase performance of emulator (read Why is the Android emulator so slow? How can we speed up the Android emulator?)

a) Use Intel Atom x86 instead of ARM

b) Use hw.gpu.enabled

I would say this makes emulator quite comparable in performance to a real device.

Update 1

Generally speaking, the idea is to configure Android PC to use tcp/ip for adb connection. And you may need to play around with network settings on VMWare or VirtualBox.

Useful links (which try to accomplish what you want

No network connection - Android-x86 on VMWare Fusion http://lkubaski.wordpress.com/2012/08/15/running-android-on-vmware-player-with-networking-enabled/ http://www.transdroid.org/2011/01/26/techpost-debugging-against-a-virtual-machine-android/



回答4:

  1. install android x86 on vmware

  2. run android terminal write command "ifconfig eth0"

  3. windows user make Environment C:\Users\user- name\AppData\Local\Android\sdk\platform-tools

  4. "adb connect IP address of the VM":5555 now run app on vmware


回答5:

To save some time: http://aztcs.org/meeting_notes/winhardsig/Android-vm/Android-VMwarePlayer-Win.pdf Good link to get started in VMWARE

Where in the case you installed in the following directory /opt/android-sdk-linux Set path variables

export ANDROID_HOME=/opt/android-sdk-linux

export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

After performing path if you see the application from typing "android" in the console your path setting is good.

create a hello world application (get the sdk installed correctly here if you have questions)

Run the hello world app

Hit ALT-F1 in the VM and use the netcfg command to know the IP address given to your eth0 device. You can then hit ALT-F7 to go back to the Android UI. Then, in your host PC, execute the adb connect [ANDROID_X86_IP] to connect the SDK debugger to your Android x86 VM; for example: adb connect 192.168.1.100:5555. If problems bounce the service adb kill-server ; adb start-server

at console change directory to /android-sdks/platform-tools then type

./adb connect 192.168.1.100 (note the 192.168.1.100 is what is required it defaults to port 5555)

I had to use the ./adb prefix and then I was configuring the VMWARE instance.

I feel allot less greasy avoiding XAML :-)