Android Tutorial: Developing Android Apps with Android X86 and Virtual Box
In this tutorial you will learn how to develop Android application with the Android SDK without a device and without using the SDK’s emulator. What? Yes it’s possible with Android X86 and a virtual machine (in our case we take Virtual Box) to setup your machine in order to test and implement your own Android apps. Learn more about this technique!
Before starting this tutorial I highly suggest to download following elements, so you can directly start to setup your programming
- Android x86 ISO generic from
http://www.android-x86.org/download (choose the android-x86-2.2)
- Virtual Box
- A correct installation of the Android SDK and ADT in Eclipse
Setting up Virtual Box for the installation of Android x86
Once you have downloaded the iso file of Android x86, it’s time to launch it. You have the choice either to boot it as a Live CD or to install it on the Virtual Hard Drive of Virtual Box.
Step 1: Installing the Virtual Box
• Install VirtualBox
• Launch VirtualBox and press on the New button
• A dialog box appears
• Specifiy Other for OS Type and Version
Step 2: We want some memory!
- Leave the Memory settings (min 512 MB)
- Create the Virtual Hard Disk (2GB)
- Click on Next till HD creation is completed
- Click on Finish
- The VM for Android was created
Step 3: Launch Android X86
The first time you launch your (by Pressing on the Start Button and having the Android line selected) VM (Virtual Machine) you will be asked if you want to boot with a CD or from an .iso image.
We are going to select our android-x86-2.2.iso file and press OK to confirm. After a short reboot you should get following picture:
- Click on Finish
Select Live CD – Run Android-x86 without installation HDPI if you want to test Android x86 or of course you can install it completely ( recommend if you are aiming to develop and store information and settings in the VM, otherwise all data are lost each time you reboot your VM).
- After a few seconds you will get following screen:
Congratulations! Now you can test and interact with Android X86!
Note: If you encounter problems such as delays while interacting with the mouse or slow animations, then adjust the memory settings in Virtual Box.
Step 4: Setting up the VM for ADB
Here’s the trickiest part of the configuration. In order for the ADB (Android Debug Bridge) to connect to our VM and so to be able to install APKs in it, we need to setup the correct settings of our Virtual Box.
- Under Settings > Network select Bridged Adapter
- Only works, if PC connected to the internet via a Router/DSL Router, otherwise no connection is possible.
You can also choose Host_Only_Adapter if you want to develop without an internet connection.
Note: The settings of the Network in Virtual Box may vary. It’s not really a big deal to change the settings, but please note that you will need to restart the Android x86 VM each time you will modify these network settings.
Step 5: Getting the Android’s VM IP address for ADB
As you certainly know, to connect to adb we need to get the ip address of the mobile phone and the port number from which we’d like to debug to.
In Virtual Box (Android x86 is started):
- Press ALT + F1 (Android Console Mode)
- Type : netcfg
- Note the eth0 ip address
- With cmd command under Windows or Terminal with MacOS type following:
adb connect 192.168.11.12
- You have now a connection over adb to your VM!
To return to the Android UI, press ALT + F7
Believe me this was the most complex part of this tutorial The connection between your PC (by extension your development themes) and the VM is now realized. Through this connection we are going to send the compiled APK file to our VM.
Step 6: Eclipse, APK and adb again…
I assume that you are using Eclipse to develop your Android applications. Let’s start with the simplest app in the world: HelloWorld. In order to install this app (and to debug it) we need to generate an APK. If you check the Eclipse project explorer you will unfortunately note that there is no APK. In fact Eclipse hides this file under the /bin/ of your projects. The solution? Go with Windows Explorer or terminal to your project’s directory and check the presence of the APK file.
Now what’s pretty cool with Eclipse, is that each time you save your files, it compiles an APK in the background and places it in the /bin directory. Nice isn’t it ? No command lines needed to compile the APK
Step 7 (option 1): Installing and Debugging (with Eclipse)
The interesting thing with the solution of launching and connecting the VM with adb is that we are “faking” a real Android device. In fact the adb connection does not check if a genuine Android hardware is connect; it will only check if there is a server responding to the adb commands. This means that we can launch the Debug from Eclipse and we will get the Android Device Chooser.
You will notice a connected device with the IP Address of your VM. This means that there is a running adb connection. Now you can press on OK and your application will be automatically installed into the Android’s VM. It couldn’t be easier!
Step 7 (option 2): Installing and Debugging (by command line)
To send your APK to the VM, we have our magic command adb, do you remember ?
So now go (with cmd or Terminal) to /bin and type following commands:
adb install -r HelloWorld.apk
The -r parameter is needed to uninstall a previously installed version of HelloWorld.
You should now directly see a new icon in your VM
and the cmd should output something like this (if you have not connected your adb before):
C:UsersMatDworkspaceHelloWorldbin>adb connect 192.168.11.12 connected to 192.168.11.12:5555
C:UsersMatDworkspaceHelloWorldbin>adb install -r HelloWorld.apk 149 KB/s (13292 bytes in 0.087s) pkg: /data/local/tmp/HelloWorld.apk Success
So now we need to debug our application. How to do that? That’s also pretty easy.
Let’s assume you have following code in your application (Ok, ok not the best debug message ):
Log.v("AndroidApp", "Hello Mat-D.com visitors!");
- Launch ddms.exe (you find it under /android-sdk/tools/ddms.exe)
- Launch your HelloWorld application from your VM and check the entry in the ddms panel
You will notice that our application was correctly started and the log file was generated
Step 8: And now?
You have learned how to develop and to debug your Android apps without a device with the VM. To increase your development work-flow, you can use some of these tricks:
- Turn off the Standby and Screen Lock option in Android (Settings -> Location and Security -> Set up screen lock)
- Launch script
Have you noticed how Eclipse does it with the emulator? Its automatically starts the application once it is compiled. We are doing the same thing by writing a small .bat file that will include the compilation and the launch of the activity:
adb install -r HelloWorld.apk adb shell am start -n com.test/.HelloWorld
com.test is obviously your package name and HelloWorld the name of your activity
Note: Please store the .bat in a safe place, as Eclipse each time it starts will clean the /bin directory of your project.
Although this, this setup obviously (mainly due to the hardware restrictions of your PC, that is not a mobile phone ) has some limitations. GPS, Sensor and Bluetooth connectivity are impossible to configure over the VM.
The most frequently asked question when I’m presenting this tutorial to Android beginners is if it is possible to use Android x86 in portrait mode: the answer is : …. well yes you could… but you need to compile Android x86 by yourself because the .iso only contains the landscape mode. Some cool guys at androidx86.org are trying to solve this problem, but if you have programmed well you application, you should support both landscape and portrait mode ;-), so it’s not really a problem.
Of course this tutorial is only meant for debugging and programming; if you plan to program Android apps you should consider buying a real Android phone as some features like GPS, multitouch, sensors etc… are not supported over the VM.
|Print article||This entry was posted by MatD on April 22, 2011 at 12:29 pm, and is filed under Android, Mobile, Techzone. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed.|
about 7 months ago - Comments Off
Here’s quick tip I wanted to share because you might face this little issue: you have eventually recorded some voice notes with the Samsung Android application and wanted to share these it with your friends or integrate it into an email and then… you found out that all your notes were recorded as .3ga files…
about 1 year ago - Comments Off
In the previous tutorials about min3D for Android we took a closer look on how to optimize the work flow from Blender or Daz3D to min3D. In today’s article you will learn how to easily change the texture of a 3D object stored in *.obj or *.3ds format. Although this sounds very easy while writing…
about 1 year ago - 7 comments
I read that a lot of people are having problems with the Unity WebCamTexture and Android. Indeed the problem comes from the fact that the texture streamed from the webcam is always flipped by 180 degrees and you will always get a wrong rotated picture of the camera (even if you turn your device (see picture)).…
about 1 year ago - Comments Off
This tutorial is about creating and compiling your own Unity GPS Plugin for Android. I wrote this tutorial in order to help those who are getting angry and fed up with missing information about the process of writing their own Unity Android plugin. My motivation was to get real speed values out of the GPS…
about 2 years ago - 1 comment
The previous post concerning min3D raised a lot of interesting questions and comments (thanks to all the visitors for their contribution!) concerning the usage of textures, the export of OBJ and the addition of features such as rotation listeners in min3D. I’ve decided to wrap up all of the comments and emails I’ve received concerning…
about 2 years ago - Comments Off
There is a lot of hype around the huge performance jump of AIR 2.7 towards AIR 2.5 when publishing for iOS and of course everybody wants to test it. Most of you have read how to overlay the inbuilt Flash CS 5.5 (AIR SDK 2.6) to AIR 2.7 (http://kb2.adobe.com/cps/908/cpsid_90810.html) but what should be done when…
about 2 years ago - 48 comments
When you want to visualize 3D content on Android phones you have several solutions and frameworks. While using Actionscript with Away3D (with GPU activated in AIR) might be the quickest solution to display low polygon models, what should you do when you want to integrate a more complex 3D view in an existing Android Java…
Calisto – a new terminal for Web 3.0 and the Internet of Services – Frisbee gesture with an Android phone to surf in the semantic web
about 2 years ago - 1 comment
Simon Bergweiler and I decided to continue our research in the field of interaction with the Internet of Services. The result is Calisto, a 40’’ multitouch terminal that can be used either over touch interactions or by speech. What’s pretty cool is that users can send (or let me say throw) picture they shot with…
about 2 years ago - 1 comment
Tick-tock, tick-tock: millions of musicians are following this sound every day. You guess it; the metronome is the musician’s best friend to stay in the rhythm while playing their instruments. For those who use a traditional metronome (also called mechanical metronome) you will notice after a while, that the beat won’t be accurate enough due…
about 3 years ago - Comments Off
I’d like to wish you all a merry Christmas with the hope that Santa Claus will bring you a lot of cool iPads, Android phones and Kinects or perhaps other IT-Gadgets like the Zhu Zhu Pets (ok it’s the low-cost Chinese version of the more interesting Furby) or a Chumby. It’s also time to ask…
Comments are closed.