Twitter: http://twitter.com/#!/farrukhn Web: http://www.wellfleetsoftware.com/farrukh Blog: http://www.wellfleetsoftware.com/blog/farrukh Farrukh has posted 1 posts at DZone. View Full User Profile

Developing Android Apps with NetBeans, Maven, and VirtualBox

06.18.2011
| 102558 views |
  • submit to reddit

I am an experienced Java developer who has used various IDEs and prefer NetBeans IDE over all others by a long shot. I am also very fond of Maven as the tool to simplify and automate nearly every aspect of the development of my Java project throughout its lifecycle.

Recently, I started developing Android applications and naturally I looked for a Maven plugin that would manage my Android projects. Luckily I found the maven-android-plugin which worked like a charm and allowed me to use Maven for developing my Android projects.

The Android Emulator from the Android SDK seemed unusably slow. Lucklily, I found a way to use an Android Virtual Machine for VirtualBox that worked nearly as fast as my native computer! This page documents my experiences.

Tested Environment

  • Dev machine: Ubuntu 11.04 Linux
  • IDE: NetBeans
  • VirtualBox: 4.0.8 r71778
  • Android SDK Revision 11, Add on XML Schema #1, Repository XML Schema #3 (from About in SDK and AVD Manager)
  • Android Version: 2.2

Overview of Steps

  1. Download and install the Android SDK on your dev machine
  2. Attach an Android Device to dev machine
  3. Configure and load your device for development and other use
  4. Create an initial Android maven project
  5. Connect Android Device to Android SDK
  6. Debug Android app using NetBeans Graphical Debuger

Download and Install Android SDK

  • Download and install the Android SDK on your dev machine as described here.
  • Make sure to set the following in dev machine ~/.bashrc file:
    export ANDROID_HOME=$HOME/android-sdk-linux_x86 #Change as needed
    export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"

Attaching an Android Device to Dev Machine

If you have an actual device that is usually always best. If not, you must use a virtual Android device which usually has various limitations (e.g. no GPS, Camera etc.). The Android SDK makes it easy to create a new Virtual Device but the resulting device is painfully slow in my experience and not usable. Do not bother with this. Instead, create a virtual Android device using VirtualBox as described in the following steps:


Configuring your Android Device

This section describes various things I did to setup a dev environment for my Android device:


Creating Initial Android Maven Application


Connecting Android VM Device to Android SDK

In order for your code to be deployed from NetBeans IDE to Android Device and in order for you to monitor your deployed app from the Dalvik Debug Monitor (ddms) you need to connect your android VM device to the android sdk over TCP as described in the following steps.

  • On Android Device open the Terminal Emulator
  • Type su to become root (your device must be rooted for this
  • Type following commands in root shell:
    setprop service.adb.tcp.port 5555
    stop adbd
    start adbd
  • Type the following commands on dev machine shell. TODO: Note that IP address below is whatever is the ip address associated with the device (see ifconfig on linux for device vboxnet0)
    adb tcpip 5555
    adb connect 192.168.0.101:5555

For details on above steps see:

http://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp

Now for the acid test whether you can deploy your app to the device from NetBeans IDE!

  • Right-click / Custom / Goal to show Run Maven dialog.
  • Enter android:deploy in Goals field.
  • Select Remember As button and enter android:deploy for its text field.

If all is well, the app will deploy to the device and will show up in its "Applications" screen.

Debugging Android App Using NetBeans Graphical Debugger

Once you can build and deploy your app to the real or virtual Android device, here are the steps to debug the app using NetBeans debugger:

  • On Device: Start the app (TODO: determine how to start app on device with JVM options so it can wait for debugger connection. This should be easy)
  • On Dev Machine run Dalvik Debug Monitor (ddms) in background: $ANDROID_HOME/tools/ddms &
  • Lookup your app in ddms and get its debug port. This is described here but does not address NetBeans specifically
  • In NetBeans do: Debug / Attach Debugger and specify the port looked up in ddms in previous step. You may leave rest of the fields with defaults. Click OK

 

Published at DZone with permission of its author, Farrukh Najmi.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Piero Sartini replied on Sat, 2011/06/18 - 1:25pm

Thanks for pointing out this possibility!

I've used the webOS SDK before and always liked their use of VirtualBox to emulate an actual device. It felt so much faster than the android emulator. If it gets only nearly the same performance with android, I am really looking forward to it. Will give it a try soon!

Michael Paitl replied on Tue, 2011/06/21 - 8:23am

Everything works beautifuly for me up to the 'Configuring your device' section above. Universal Androot installs fine (latest version) but when you try to root the device, it comes back with the message 'Cannot root this device :('. Did you use any particular version of Universal Androot? 

Thanks

Farrukh Najmi replied on Tue, 2011/06/21 - 10:04am

Here are some issue I have not found a solution to yet. If any one has solutions to these please post.

Farrukh Najmi replied on Tue, 2011/06/21 - 10:09am in response to: Michael Paitl

I do not recall doing anything special. Unfortunately I do not know how to tell the version post facto. I do not see any app named Universal AndRoot installed. If any one knows how to find out I can check for you. Feel free to try a different rooting solution and report your finding.

Fabrizio Giudici replied on Wed, 2011/06/22 - 10:05am

More than 10,000 reads in a few days, Farrukh... congrats for this post. It's one of the most interesting things I've recently read. I've been able to set up 80% of the stuff (then I went to sleep ;-) I think I'll be able to complete the job with the next free two hours. This approach is definitely one more useful way to work with Android. Thanks.

Mary Smith replied on Wed, 2011/06/22 - 3:50pm

Good article, it'll help me with my project Google Translator

Marc Ende replied on Tue, 2011/08/23 - 2:31pm

Great article. By the way: Do you've got any issues when trying to edit main.xml or strings.xml? When I do that in netbeans they're not saved when saving them.

Angel Afirce replied on Sun, 2011/10/09 - 9:48am

I cant wait to try these applicationsf rom these software giants. I beleved the competition amongst them  will ensure utmost quality.

custom doors

Matt Coleman replied on Fri, 2011/11/11 - 5:39am

oh my Apps...i cant wait for netbeans apps graphic artist buffalo

Amey Hendra replied on Thu, 2011/11/17 - 2:39am

I guess editor/IDE is just personal perference more than anything else in this case, but it always a good idea to check what other people into. Netbeans is getting better last time I look at it when they send me the new release, but personally still perfer eclipse.

regard

Kiranatama

Ryan Fitz replied on Mon, 2011/11/21 - 2:05am

android apps are way better than iphone apps Fitzmagic shirt

Andres Mattia replied on Tue, 2011/11/22 - 11:23am

"i cant wait for netbeans apps" i fully agree Piscinas Prefabricadas Precios Cesped Artificial Barato

Javier Godino replied on Wed, 2012/03/21 - 8:30pm

Hi,

 Good article!!!

Is there a possibility to use a external camera to web camera with VirtualBox?

Thanks!!!

Javier 

 

Matt Coleman replied on Thu, 2012/05/24 - 1:23am

wow!im am using Android,.is this available now?

 website design buffalo

Mateo Gomez replied on Fri, 2012/05/25 - 1:02am

this is exciting..with so many apps now this is something

 mexican bread

Farrukh Najmi replied on Wed, 2012/06/06 - 1:50pm

In section above "Connecting Android VM Device to Android SDK", when connecting to your physical or virtual device via adb you may find the adbwireless app from google Play Store to automate the process and make it trivially easy.

Berton Jain replied on Sat, 2012/07/14 - 11:53pm

good to see the Android Apps with net.. I need to see my bridal lehenga pages on Andriod.

Frank Verdin replied on Sun, 2012/09/23 - 8:05am in response to: Matt Coleman

Si vous débutez en chercher un, votre première chose seulement je peux vous suggérer est de connaître votre budget. Je suppose que vous êtes à cette action d'une machine afin de la maison ou avec un poele a bureau, mais aussi ne pas commencer un propre café tassimo . Machines concernant tassimo adaptés pour une emploi personnelle gamme de tarifs de quelques centaines pour obtenir dollars à quelques très nombreux. Donc, placer une limite de prix concernant l'avance, sinon vous en votre for intérieur allez trouver un coût maintient à votre hausse rampante que vous découvrez de nouveaux styles et de nouvelles fonctions. Pour une machine de belle qualité, s'attendre concernant passer entre deux mais aussi cinq cents dollars au sein de une bonne enseigne (Gaggia par exemple. ) La plupart des machines à café nespresso sous-cent généralement ne produisent pas plut?t de pression pour créer un senseo bien. Elles ont la possibilté de paraître et ressembler à ceux que vous entendez dans le café tassimo , mais comme une grande majorité des choses que vous avez vraiment acquérir ce que vous payez.
________
machine expresso

Steve Sdas replied on Wed, 2012/10/10 - 10:39am

Thanks for sharing such useful tips with us. I admire the valuable information you offer in your post. It helps me a lot to enhance my knowledge, I really like the way the writer presented his views.. Mysitevote Bookmarking

Steve Sdas replied on Sat, 2012/10/13 - 3:26am

I had my tutor arrange this in the Berber language the day before so there would be no misunderstanding.Share It

Steve Sdas replied on Sat, 2012/10/13 - 7:33am

It's never too lately to meliorate your information and your listing has me.flexispy reviews

Stork Club replied on Fri, 2012/10/19 - 1:47am in response to: Steve Sdas

I have shared it Steve thanks for this


 club stork

Steve Sdas replied on Thu, 2012/11/01 - 9:29am

I would but say to you all "impressive information" houses for sale in fife

Steve Sdas replied on Sun, 2012/11/11 - 8:23am

I found it best to create stub project structure using the maven-archtype-plugin and the archtypes at get followers for instagram

Steve Sdas replied on Mon, 2012/11/12 - 1:04pm

The caliber of collection that you are providing is but marvelous. the topiary

Uilly Tocky replied on Mon, 2013/01/14 - 4:30am

This was the first place that told me the answermodern warfare 3 cheats

Uilly Tocky replied on Sat, 2013/02/02 - 6:46am

Nice to see the quality information presented in an easy and understanding manner. nursery school program

Uilly Tocky replied on Sun, 2013/04/14 - 10:28am

Your writers are enormously tremendousGanhar Dinheiro Winner Manager

Uilly Tocky replied on Fri, 2013/05/24 - 1:12am

I am absolutely amazed at how terrific the stuff is on this site. I have bookmarked this webpage and I am visiting the site in the upcoming days. Great job! Philadelphia Realtor

platnumcn kirk replied on Sat, 2013/07/20 - 5:32am

This post is very helpful and shows that you have a lot of knowledge on the topic. Do you have any others www.dxtechinc.com -

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.