Test android app on Virtual Box from Android studio - android

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.

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)

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.

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

Here's how it works for me.
I just connect my android phone with USB to my host (Windows 10).
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.
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.
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.

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
:-)

Related

Android Studio no longer recognizes LG G Stylo

I need to know how to make Windows 7 forget it ever connected to my LG G Stylo phone. I have three devices that I use in Android Studio development. For some reason, this one is no longer being detected by the ADB. Something has happened to make it no longer show up, because it did a couple of weeks ago.
AS's ADB will detect my other two devices, and this device shows up in the in the ADB on another computer. I have tediously gone through the registry and removed everything referencing the Stylo, but it still will not show up in AS's ADB.
Thanks for the help!
John
To start, I have just purchased the LG Stylo 3 plus and ran right into this situation. TO repeat the basics you need
With Android Studio shut down...
Turn on Developer options (tap 7 times on build number in settings
(Settings>System>About Phone>Build Number
Turn on USB Debugging in Developer Options
(optionally) check on the type of USB connection, MTP or PTP should
work
(Optionally) Because I did it, also do a revoke USB tap.
Here was the key for me. I needed to install the LG USB Windows Drivers for my Windows 7 (I'll try 10 tonight and update). Go to this page
LG Drivers and firmware
and either type in model number or browse to find device. LG has a nice interface to install the Windows Drivers. I recommend the Support tool to verify the device as the up to date drivers as well. Start Android Studio and to test I just started the app in debug mode and went through the process of setting up ADB for using the new;y connected device.
Developer options" has to be ON in order to make AS see the device
If even though device manager you can't saw the device, Windows couldn't find drivers.Maybe the drivers are hidden on the device otherwise download it and install it.
If that doesn't work:
Shut down
Hit F8 (or whatever gets to startup options screen on your computer)
Disable Driver Signature Enforcement.
Run driver

Android Studio - No USB devices detected

I tried to play Android Studio 2.0 with my mobile without success, what I did are:
In my mobile, Apps/gear icon/Settings/SYSTEM/{} Developer options/ Android debugging/, enable the Android Debug Bridge(adb) interface (set tick).
After plug in my mobile to my PC with a USB cable, I found A0001 in my Computer folder. Within A0001, I can see the files in my mobile.
In my PC, run Android Studio/bin/studio.exe, "Select Deployment Target" window shows with message "No USB devices or running emulators detected"
I have tried two different USB drivers but got no lucky.
Perhaps I should tell Android Studio where is my USB driver? But, how?
Can you help?
I had the same problem too and I managed to resolve it this way.
First, enable debugger mode in your android device.
Go to Device Manager from Start Menu and try to find ADB Interface with an error symbol on it. This generally happens because windows sometimes fail to load all the mobile device drives.
Next, Go to http://adbdriver.com/downloads/ and download the driver installer, unzip and run it.
Now go to Android Studio and you should find that everything is working fine.
Chill....
same here... but I hope you can avoid this problem the same way I Did.
There is an "universal ADB Driver for all Android Devices".
Yep... sounds like magic.
Just follow this link.
https://devs-lab.com/usb-adb-drivers-for-all-android-devices.html
Fun fact there is no "Step 5" in that article so I'll give you.
you have to enable "USB Depuration" from "Developer Options" connect your cellphone to computer as a "MTP storage" , after windows detected your cellphone as a "Portable Device" Execute ADBDriverInstaller.exe (that downloaded from devs-lab)
check the device list and your cellphone will say "Driver incorrectly", select your cellphone and press install.
Step 6: Once the process is completed, you’ll see something like the image that appears there (in the link).
I hope that somebody else work this
Go to Run > Edit Configurations...
Under Deployment Target Options select Show Device Chooser
Dialog from the drop-down-list
See picture for reference
After struggling with this problem for a while, I found that there are certain cables that can only charge your phone, and even though they seem to be working, they do not allow your phone to be used as a "Media Device" and therefore Android Studio does not detect it.
Go to
Tools | Android | Enable ADB Integration
Make sure it's enabled. When I upgraded to 2.X it was for some reason disabled for me and it took me hours to find it.
I just cannot beleive why it is so difficult! let me try again and please check my steps again:
I installed Android Studio 2.0, then run Computer/OS(C:)/....../Android Studio/bin/studio.exe.
The Android Studio window appeared in my working area Computer/OS2(J:)/Users/MyAccount/Desktop/.
I connected my mobile with my computer, Cpmputer/A0001/ appeared, from it, I can see the files in my mobile.
I clicked the run icon in the Android Studio window, a "Select Deployment Target" window apeared with message "No USB devices or running emulators detected".
(I got two USB ports and tried both but got the same result.)
Finally found the solution : )
1. Install device’s required driver. (for me it was motorola device
manager)
2. Download Google Usb Driver from SDK Manager
3. Open your phone's setting->developer options and turn on USB debugging.
4. connect your device to computer
5. Go to Device Manager from Start Menu and try to find if there is ADB Interface with an error symbol on it.
5.1. If yes, then right click on the ADB interface->Update driver
software->Browse my computer for driver software-> Let me pick from
a list of device drivers on my computer->Select Motorola ADB interface
5.2. Now one confirmation will pop up in your mobile, accept it
5.3. Now you should see no error mark beside the ADB interface in your
device manager
There are 3 steps to set up your phone for debugging:
1) Change your phone to developer's mode by going to Settings, About Phone, Software Info, Android Version - tap at least 7 times on the Build Number text. You will get a message saying you are now a Developer.
2) Enable USB Debugging in Settings - Developer Options. Make sure you are not connected to your USB port to see the USB Debugging option enabled, otherwise it will be disabled.
After you plug in your USB, swipe at the top of your screen, you will see USB Debugging on.
3) Make sure USB connection is set to Photo Transfer (or MTP - Transfer photos and videos). After you plug in your USB, swipe at the top of your screen, and you will see Tap to change USB options on the menu. Tap it, and select Photo Transfer option.
Perhaps your mobile manufacturer does not provide the proper driver.
Go to Device MAnager and look for: Android Composite ADB Interface. If it's there, the driver is properly installed. If not... You and I are on the same "wagon"...
I tell you: Acer? Never again.
USB debugging somehow got turned off under developer options on my Samsung. Turned it back on and it worked, but only by clicking on "debug app" instead of on "run app".
With me, when connecting the mobile to the pc, three options appeared on my mobile.
Charge this phone
Transfer Files
Transfer Images
I thought I should select "Transfer Files", but it dd not work
But it only when works I choose "Charge this phone"
Few ways to resolve this problem.
Case 1: Install PdaNet+ in your system. (worked for me).
Case 2: Enable the USB debugging option in your mobile. Setting > developer > Check "USB Debugging".
Case 3: Change from MTP to PTP.(sometimes vise versa works).
Question is Your development sdk no mobile version android sdk Platform.
For example, my android phone system is 6.0, i need download sdk Platform 6.0.
First, try to revoke the usb sessions in the developer options, then try downloading an oem usb driver
If then doesn’t help you can try opening the device manager on windows, right click on your phone, select uninstall. This worked for me if I had the same issue.
I couldn't find my android phone or any USB device I connect to my windows laptop on the hidden icons. Well, my mouse and phone could charge but I can't seem to see my phone in the File Explorer option.
I prefer running Apps using my phone rather than emulator in Android Studio and yet I couldn't see my phone when I connect using the USB.
This helped me solve all my problems after several hours of searching for solution.
Download Universal ADB Drivers - One size fits all Windows Drivers for Android Debug Bridge
Please use this link: https://adb.clockworkmod.com/
I hope this works for you like magic!
I can see all the devices I connect using the USB cable and my mouse receiver.

Visual studio android emulator will not start fully

I create a blank cordova application in visual studio 2015 and start debugging with the visual studio android emulators (first with the lollipop and then kitkat). XDE starts and the screen displays OS is starting.... It stays like that for quite a while until it displays
The emulator is unable to connect to the device operating system;
The device did not response to the connect request.
Some functionalities might be disabled'
After closing the dialog, it stays there forever until I kill the emulator. Killing the emulator triggers an error from visual studio.
Could not start emulated device 'VS Emulator Lollipop Phone'.
When I open hyper-v, I see the vm in the list and shown as running. When I connect, I see the console screen as below
I know this issue has been around for a while now, but I have just found a new solution for people who may still encounter this issue...
I had the same issue (stuck on "OS Is Starting") for API v 21 & 22. API v23 images would start, but could not debug - the app would crash as soon as it launched.
The following fixed the issue:
Shut down the emulator
Open Hyper-V manager
Go to the settings for the Android Image
Expand the "Processor" configuration node
Go to the "Compatibility" node
Check the "Migrate to a physical computer with a different processor version" option
Apparently it has something to do with newer Processor architectures being incompatible with the Android images or something like that - don't really care, as long as it works :)
I was running into the same issue. I did try to disable OpenGL by deleting: GuestDisplayProvider = "VsEmulator.OpenGLGuestDisplay" in xdesku.xml, as suggested in other answers.
At first, the virtual machine would boot up (you could connect to it from Hyper-V manager), but the emulator window itself would not connect to the machine (stuck on "OS is starting", then failing after a looooong while with the following message: "The emulator is unable to connect to the device operating system: Couldn't auto-detect the guest system IP address. Some functionality might be disabled.")
This answer https://stackoverflow.com/a/31698124/1010492 and that one https://stackoverflow.com/a/14402740/1010492 helped me solve the connectivity issue, and I was able to have the Virtual Machine displayed inside the emulator window.
However, the emulator wasn't working properly (scaling issues, no Home, Back, etc. buttons) until I put back the line "VsEmulator.OpenGLGuestDisplay" and after removing my profiles and rebooting a number of times.
To sum up, if you are encountering the same issue on an Hyper-V enabled computer, you may want to try the --over conscious-- following steps:
Ideally, uninstall any other Virtualisation software such as VMWare, Virtual Box and VPN clients such as Cisco VPN (if you cannot
do that, please be vigilant at step 13)
Reboot
In the "Visual Studio Emulator for Android" dialog, delete all installed device profiles
Remove All Hyper-V virtual switches - go to Hyper-V > Virtual switch manager > Remove all virtual switches
Run XdeCleanup.exe (usually in "C:\Program Files (x86)\Microsoft XDE\10.0.10240.0")
Also remove any extra virtual network adapters left in "Control Panel > Network and Internet > Network Connections" (after following
the previous steps, you should normally be left with only physical
adapters)
Make sure Network Sharing is disabled on all network adapters (right click, Properties, Sharing, untick "Allow other network users
to connect through this computer's Internet connection")
If ever you deleted the line GuestDisplayProvider="VsEmulator.OpenGLGuestDisplay" in xdesku.xml
(usually in "C:\Program Files (x86)\Microsoft
XDE\10.0.10240.0\SKUs\Android"), NOW IS A GOOD TIME TO PUT IN BACK.
Reboot
You may want to try to repair the emulators: go to Programs and Features > Microsoft Visual Studio Emulator for Android > Change and
hit "Repair" (although I have to say this always fails for me)
Reboot
Open the Visual Studio Emulator for Android, and install then run one of the profiles (eg: 7'' KitKat (4.4) XHDPI Tablet -- Similar to
Asus Google Nexus 7)
It may already work, but if not you should make sure that your network adapters are setup properly. Stop your emulator, then Go to
Control Panel > Network and Internet > Network Connections, and right
click the vEthernet adapters, then Properties and make sure you only
have the following boxes ticked in the Networking list (as explained
in Interference from other virtualization or networking software and
drivers: Client for Microsoft Networks, QoS Packet Scheduler, File
and Printer Sharing for Microsoft Networks, Microsoft LLDP Protocol
Driver, Link-Layer Topology Discovery Mapper I/O Driver, Link-Layer
Topology Discovery Responder, Internet Protocol Version 6 (TCP/IPv6),
Internet Protocol Version 4 (TCP/IPv4)
Reboot
Try to start the emulator again in "Visual Studio Emulator for Android"
If it still doesn't work, try to delete and recreate the profiles, and loads of reboots...
There are probably some redundants steps here, but I think it covers everything you should try (the key seems to be making sure that the network adapters are setup properly). If I've missing some things or if you think some steps are useless, please comment.
After alot of searching I got this working. Hope this helps. I found it in the comments on MSDN Article for Android Emulator with Visual Studio 2015
The new images might work if you disable OpenGL by going to Program Files (or Program Files x86 if you're on a 64-bit machine) \ Microsoft XDE \ 10.0.0.0 \ SKUs \ Android \ xdesku.xml and deleting this line: GuestDisplayProvider = "VsEmulator.OpenGLGuestDisplay". However, without OpenGL turned on you will not be able to take advantage of many of the new features
On my system I got it working again after enabling the disabled vEthernet (Internal Ethernet Port Windows Phone Emulator Internal Switch) again.
I didn't have to reboot.
I went through the steps in #Gyum Fox answer and still no joy for me.
While the Visual Studio Emulator for Android creates the first emulator instance, several virtual network switches are also created. For a laptop, typically three vEthernet instances are created; one for the wired LAN, one for the Wi-Fi, and another internal virtual switch for guest to host connections.
In my case, the vEthernet for the wired LAN was created successfully and then the Visual Studio Emulator for Android process would hang. This is observable from the Hyper-V Manager and the Virtual Switch Manager action.
Using the Virtual Switch Manager I successfully created the missing Wi-Fi virtual switch with these steps. Well, ultimately it worked. Read on.
Under the Virtual Switches list, select New virtual network switch…
Under What type of virtual switch do you want to create?, select External.
Under the External network: drop-down, select the Wi-Fi adapter.
Click the Create Virtual Switch button.
Change the Name: to match the name of your Wi-Fi adapter.
Click the Apply button.
In my case though, after clicking Apply, a failure message indicated the Wi-Fi adapter was bridged. Hmmm.
I started the View Network Connections control panel applet and the Wi-Fi adapter did not show it was bridged. (When a network bridge exists, the Status column has the word Bridged appended.) I suspect there was some dusty digital bits lurking somewhere in the registry.
Here is what cleared the issue for me.
Right-click on the Wi-Fi device.
Select Add to Bridge.
Right-click on the Wi-Fi device, again.
Select Remove from Bridge.
Now, go back up to the steps to create the virtual switch for the Wi-Fi network. The steps should complete successfully now.
And now, you can go back to creating the Android emulators you want.
One final thought… If you aren’t seeing any virtual switches being created, I suspect that could mean the wired LAN might have the dusty digital bits hanging you up. In that case, I’d try add-and-remove-from-bridge trick on the wired LAN adapter to see if that clear things up for you.
And, now I suppose that just doing the add-and-remove-from-bridge trick on the network adapter without creating the virtual switch might suffice. For me, the creation of the virtual switch was proof that the issue was corrected. YMMV ;-)
I found my issue was related to the windows firewall with some enterprise policies my company applied to all PCs. Once I stopped the Windows Firewall service it worked just fine.
I also had this issue and it was not just for android emulators but for all windows phone emulators.
This is what i did to fix the issue
Uninstall the Genymotion and Virtual Box (I had these in my system and this did not solve the issue)
Removed all Virtual adapters. this is the tricky part. None of adapters could not delete from Hyper-V virtual Manager. I had to use powershell and run
remove-vmswitch -Name "The name of V Adapter" -force
Also, from this I was not able to delete all the adapters and I found this link "https://social.technet.microsoft.com/Forums/windowsserver/en-US/e49df568-4f4c-47b7-b30c-952d1e26ca58/cant-remove-failed-virtual-switch-from-hypervs-virtual-switch-manager?forum=winserverhyperv" and deleted all virtual adapters
reboot the computer
After this there was not any v adapters in Hyper-V virtual Manager
Run the XdeCleanup.exe (just in case)
Also, I disabled the firewall from my virus guard
After this I was able to run the emulator from "Visual Studio Emulators for Android"
I'm adding a separate answer though the insight provided by Gyum Fox provided the clues I needed to try other stuff ...
[NOTE: The last time I was able to use the emulators (~3 weeks ago) I had wireless disabled and was using a wired connection on my Dev laptop. I ran out of space on my switch so re-enabled the wireless as the sole connectivity option. This may be totally coincidental, but read on and I'll let y'all decide.]
After following Gyum's steps without success, I decided to turn off the wireless and then try launching the emulator.
Wouldn't you know it ... it worked without an issue! 8-}
Once I had the emulator running, I re-enabled the wireless and the emulator picked up the connectivity.
I'm not a network guy so I'm not even gonna attempt to understand. It's a minor PITA but hey ... if it works!!! ;-}
On my machine I could start the emulator but I got an OpenGL error when trying to deploy and debug. I realized my issues started after I installed Docker. On a whim I decided to shut down Docker and disable the vEthernet (DockerNAT) Network Connection. This fixed my issue. Now, whenever I need to use the Andoird emulator I have to shut down Docker. Then when I'm done debugging I enable/restart Docker.
One of the reason I was having this issue is that I did not install the Android SDK on the default location. So I had to follow these instructions in order to be able to debug my application: https://msdn.microsoft.com/en-us/library/mt228282.aspx#ADB
I had to create the folder "Android SDK Tools" and add the Key "Path" with the value to my SDK, which in my case it was "E:\Android\Android_SDK"

Connect to VPN in Genymotion Android

I'm trying to Configure and Connect to VPN in Genymotion Virutal Device, I can configure VPN connection in the Virtual Device but unable to Connect, No error showing.
I used same settings in my PC and Real Android Devices, Its working fine in the device and PC.
I think Its problem with VirtualBox, But I don't know how to resolve it
System Details:
OS: Linux Mint 32Bit
Genymotion Version : 2.1.1
Virtual Device: Galaxy S4 - 4.3 - API18 - 1080x1920
Genymotion use Virtual Box, you need open this and set the connection Bridged instead NAT, power on the Android Genymotion VM in Genymotion APP and set VPN.
Solution 1 :
Install a VPN application on the virtual device like VPNSecure or SecureVPN or the one from your provider, otherwise you could use OpenVPN application
Solution 2 :
Connect to your VPN in you host machine (you can disable binding your vpn connection to avoid passing through all the application)
Then you can force player.exe and genymotion.exe to use a specific network card (your vpn virtual network card/ip) a solution could be forcebindip
http://old.r1ch.net/stuff/forcebindip/
ForceBindIP.exe -i 192.168.1.25 "C:\Program Files\Genymobile\Genymotion\genymotion.exe"
where 192.168.1.25 is the ip of the interface you want to use
This application redirect any connection to a specific interface and keep it there.
Note : As this program is source closed you could be skeptical in a perspective of using it all the time, i personally disassembled it and checked every action and it seem that it's a clean application.
Solution 3 (Best):
On top of genymotion, install virtual box (i think you need to have virtual box before using genymotion) then when you run virtualbox application it will display your virtual android device, you can then set the different advanced setting directly on virtualbox application like so :
This worked for me:
Open virtual box, find the Genymotion device -> settings -> network.
I had two adapters set much like in initika's answer (3rd option screenshots). What I did was close the device, then disable the first adapter (host only) and leave the second adapter set to NAT. Then I restarted the device. and saw that it could now access the private network.
I had a similar issue and what I did to solve it was:
Open virtual box, find the Genymotion device -> settings -> network.
Choose the "Adapter 2".
Change the Attached to option to "Bridge Adapter".
Select the network card from your PC.

How to use Android OS VirtualBox as device in Eclipse

I found this tutorial on how to run Android OS here: http://www.javacodegeeks.com/2010/06/install-android-os-on-pc-with.html
Has anyone tried to use the set-up as a replacement for the emulator? If so, how did you do it?
I haven't used the guide you link to, but instead downloaded an eeepc image from the Android x86 Project. The steps I followed are:
Install Android to a virtual PC - I used a 64bit virtual machine, enabled all the hardware virtualisation, and used the PCnet-FAST III virtual network adapter in bridged mode - see image 1
Disable host mouse pointer integration - this will allow Android to display it's own mouse pointer so you know where you're clicking.
You need to work out what IP address the VM has, so that you can connect with adb connect <YOUR_VIRTUALBOX_IP>. I do this by logging into my router and identifying the IP of the device that shares the port with my laptop, since that's the Android VM using bridged networking. See image 2.
You are supposed to be able to use VBoxManage commands to identify the IP of the guest, but I've never gotten those working, so the router method is the only one I have that works.
Performance is pretty good - much quicker than running hte ARM emulator, though of course, you can only run Android versions that have been compiled for x86.
You are supposed to be able to use VBoxManage commands to identify the IP of the guest, but I've never gotten those working, so the router method is the only one I have that works.
Hit Alt + F1. when the root#android prompt comes up, type netcfg and press enter. That will show you the IP address. Hit Alt + F7 to get back to the GUI.

Categories

Resources