7

I have a very specific problem. I am trying to create an Android app for educational purposes, together with a friend of mine. The problem is, my processor does not support VT-x, which is essential for using an AVD, and my Android phone is considerably old so it can't really take much.

Therefore, the one solution I have in mind is using VirtualBox to create a 32-bit Android Virtual Machine and test my app there.

The problem is that, unlike an actual Android device and an AVD, a VirtualBox Android VM does not have, for what my knowledge is, an obvious way of being connected with Android Studio for testing each new app build.

So, what I am asking for is exactly that: a way to immediately test the app I have written in Android Studio in my Android Virtual Machine I have created on VirtualBox, including any workarounds that effectively allow me to immediately test the app on the VM, other than finding a way to make adb work with it.

Noob Doob
  • 1,757
  • 3
  • 19
  • 27

5 Answers5

16

I see I'm a bit late on this one but I figured it out. I am using Windows 8, running Android x86 (4.4 r1) on VirtualBox.

1. Set up a Host-Only adapter so that the VM has access to your network; You can set this up only when the Android image is off. Basically just go into your settings, click on Network, and select Host-Only Adapter in the drop-down labeled Attached to. For Adapter Type select PCnet-FAST III. Check the box next to Cable Connected if it isn't already.

2. Set up an NAT Adapter by selecting a different Adapter tab and for Attached to select NAT. For Adapter Type select PCnet-FAST III again. Check the box next to Cable Connected if it isn't already.

3. Enable Developer Mode by starting up the Android image, then going to Settings > About phone/tablet > Build Number. Click on Build Number 7 times. You should see a pop up that tells you how many more times you need to click to get into Developer mode. Credit to RMP PianoTuning's answer below

4. Get the virtual Android's IP address by going into Settings > About phone/tablet > Status > and then scrolling down until you find your local IP Address. Remember this number, you'll need it for the next step.

5. Start up Android Studio and go into the console; it should be one of the options in the bottom-left corner. Type in adb connect (IP address from step 4). Take a deep breath and hit enter. If it says

connected to (IP address)

you are ready to rock! When you run the app within Android Studio, your virtual Android should appear as Innotek GmbH VirtualBox, or something like the same. Select that puppy and enjoy your new, easy-to-test-on emulator. Its even Bluetooth Compatible! (but thats a whole 'nother story... google it)

omikes
  • 8,064
  • 8
  • 37
  • 50
  • 1
    I did everything but in the end it says "unable to connect to 192.168.0.104". Why so? – Syed Danish Ali Dec 29 '15 at 14:50
  • 1
    Have you double checked your virtual android's ip address? it might have reset when you restarted it. – omikes Dec 29 '15 at 15:17
  • Something really weird is going on here. After writing down my android's Ip address in step 2, I set up my network adapter with _Attatched to_ as _NAT_ and when I turn it back on, it gets an Ip address completely different from the previous one. Both network adapters are there and everything I did was as written in the above answer. Now I don't know how to make that Ip address a static one. – Syed Danish Ali Dec 29 '15 at 17:17
  • 1
    for step 3, instead of forwarding port 192.168.1.XXX, just forward an asterisk (*) instead. this should forward all ports to the same ip address on the other side. this way you can simply check which ip android is on and connect to that instead of a set ip address. – omikes Dec 30 '15 at 21:14
  • Hi. I tried all of your steps and was able to connect via adb. However I can't install my test app. In Android Monitor I get: `Dropping log because Clearcut could not write to store. SQLiteCantOpenDatabaseException: unable to open database file (code 14): , while compiling: PRAGMA journal_mode` In Grade Build window I get `AAPT process not ready to receive commands` – nettie Nov 27 '16 at 22:16
  • Additionally to get 'Innotek GmbH VirtualBox' to appear, I had go to the drop down menu next the green run/arrow button (below Tool, VCS menu) and change it from MainActivity to app. Thank you so much for this! – gimmegimme Feb 09 '17 at 07:22
6

Now a virtualbox isn't an answer to your need.

here are some alternatives,

Genymotion http://www.genymotion.com/ which is an easy to use android emulator , i suggest you look into it. based on virtualbox , can be integrated into android studio with ease . needs an AMD-V proc if not a VT-x . If the processor does not support these, the emulator still works, but your emulated device will only be able to use one CPU.

The other option is adb over wifi, which will let you use your phone without doing the dropbox step http://forum.xda-developers.com/showthread.php?t=1685736. For this to work you will need root though.

Noob Doob
  • 1,757
  • 3
  • 19
  • 27
TheAnimatrix
  • 566
  • 1
  • 6
  • 19
2

I was able to follow OMiKeY steps and get my app to run in VirtualBox, the part he leaves out:

In your Android simulated device, you have to enable Developer mode. Goto 'Settings' -> About Phone/Tablet->Build Number. click on Build Number 7 times. For me I got pop up that told me how many more times I needed to click to get into Developer mode.

After that i re ran the adb connect XXX.XXX.XXX.XXX command

  • 1
    Did you also have to activate the setting for allowing programs from unknown sources? – omikes Sep 24 '17 at 21:04
  • No, just Enable Developer mode. I did not go into the Developer Options menu. Once I got it working, I install VirtualBox on second computer and it worked the same. – RMP PianoTuning Sep 29 '17 at 19:42
1

Here's how it works for me.

  1. I just connect my android phone with USB to my host (Windows 10).

  2. Then make sure the USB phone is found from within the guest OS (ubuntu desktop 18.04 in VirtualBox 6.0). (VirtualbBox app: Devices > USB > check the USB corresponding to my phone). Once it's recognized by ubuntu, there will be a phone icon showing up on the desktop screen.

  3. Next, I start android studio (v3.3.2); once that is complete, from the Terminal window (Android studio: View > Tool Windows > Terminal), I type in: adb devices, which would list the devices attached and my phone is on the list.

  4. Now I run the app for a test (monitor my phone and confirm if there's prompt)...and the app shows up on my phone. Hope this may of help for others.

Harry
  • 1,147
  • 13
  • 13
1

If you are running Windows, open the specific port in Firewall. In VirtualBox in your Android instalation Settings->Network Adapter 2 Tab - Port Fowarding and create a rule with Protocol (TCP) - Host IP (Your IP) - Host Port (in my case 5555) - Guest IP (Same Step 4 - Check your IP ) - Guest Port (I put the 5555 too). Ok! Now I can run my Apps in VM.

AppData\Local\Android\Sdk\platform-tools>adb connect 192.168.0.101 connected to 192.168.0.101:5555

Running devices: innotek GmbH VirtualBox

:-)

tetraetila
  • 11
  • 1