Android development on a netbook

Netbooks are perfect devices for web browsing, but there are times when they have to face much more serious challenge.

I'm satisfied with my nebook performance (Acer Aspire One, Linux/SSD version). I've modified default Linpus Linux Lite, stripping all the Acer's soft, and replaced it with bare-bones xfce4.4 + compiz fusion with all sorts of fancy effects + my favourite linux programs, compiled from source. Nevertheless, I preserved the default kernel and kernel modules to ensure all hardware works just fine. As a result, system boots in ~15 seconds, feels fast and impressive (due to compiz fusion).

This setup proved to be suitable for web browsing, occasional word processing (I tend to use Google Docs for word processing, so use OpenOffice only when I'm offline), ssh-ing and Ruby on Rails development with Vim. I even used netbook to develop some J2ME applications with Netbeans 6.5. The powerful IDE feeld snappy, emulator booted quickly, the only real annoyance was the lack of "Home" and "End" keys on the keyboard.

But then I faced the need of some Android development on a netbook. Normally I use my desktop for Android development. However, I'm currently teaching a University course of application development for mobile platforms, and I had to demonstrate Android development to my students. For my lectures, I usually take a netbook with me, connect it to multimedia projector, and program something there to demonstrate how this or that mobile platform programming goes. I was so assured in the netbooks performance that I hadn't even tested Android development on it, just set the environment. The environment was a typical one: Android SDK and Eclipse Ganymede with ADT plugin.

So, after a talk about Android architecture principles I supposed it was time to demonstrate some of them in practice and started Eclipse. It feeled slow, to say it mildly. "Nothing special", I thought, "Ecipse feels slow even on my desktop, it is slow by design!". I've created an Android project with ADT plugin and then came the next annoying thing - netbook screen appeared to be just too small for all Eclipse panels, they occupied almost all of the screen space, leaving only a tiny fracture of it for source code editing. After closing almost all of the panels, I was able to free some screen space for code editor, so it became acceptable. Having explained the project directory structure to my students I decided to run the project to show them how Android emulator works. Then came the worst part: Android emulator loaded terribly slowly, it had been loading for 5 minutes or even more, bringing netbook to it's knees in the process. Another issue which I noticed during the emulator load - default emulator skin (HVGA-P), that Eclipse starts, doesn't fit netbook 1024x600 screen resolution and there's absolutely no way to resize it to fit the screen. The most vital parts of Android emulator - it's "menu" and "home" buttons - don't fit in the screen, rendering emulator almost useless! (see screenshot below)

Note that in addition to emulator and Eclipse I was running Adobe Reader with ~6M pdf file loaded and Firefox with 5+ opened tabs. This made my netbook super-slow, sometimes it simply hanged for 5-10 seconds. Not to say, those lecture wasn't very productive: apart from architecture overview, the only thing that we were able to examine was simple "Hello, World!"-type application...

Naturally, after such a failure my first thought was that netbook is completely unsuitable for Android application development. But what seems to be an impassable obstacle for normal person is an interesting challenge for a true geek! So, I decided to optimize my Android development environment until it becomes usable on a netbook. My idea was to avoid using Eclipse (as it is a CPU and memory hog), resize emulator to fit the screen and disable Compiz Fusion (as it tended to make emulator much slower in my experience). Speaking in advance, I was able to implement this idea with little effort, so I decided to write a little guide so that my geeky readers could try to set up such an environment for themselves and happily develop Android applications on their powerful netbooks:

First of all, you should tune Android emulator to fit 1024x600 netbook screen. For this, start the emulator from command line with the following options:

emulator -no-boot-anim -verbose -skin QVGA-L

Here "no-boot-anim" is used for faster boot time, "-verbose" is to see if everything goes smooth and "-skin QVGA-L" is to call skin with smaller screen resolution than default one (320x480 portrait HVGA-P vs 320x240 landscape QVGA-L). Such an emulator perfectly fits the small netbook screen; the only thing that doesn't fit the screen is a part of QWERTY keyboard, which doesn't matter anyway as you may use regular keyboard instead. As a side note, "HVGA-L" skin also fits the standard netbook screen, so you may use it as well. Personally, I prefer QVGA-P for it's geeky look and for the fact that "-no-boot-anim" option actually works for it, so it boots much faster than "HVGA-P" device.
The next step is to generate the project skeleton files. It is easy with the help of "activitycreator" script, provided with Android SDK (in "tools" directory, it might be wise to to add this directory to your $PATH):
activitycreator -out my_cool_project com.mycompany.android.MyCoolActivity

It creates exactly the same files that are created by eclipse ADT plugin "new project" wizard (it uses activitycreator internally).After that edit project files with your preferred tools (for example, my preferred editor is Vim). When source code is ready, build it, sign and install on the device by running the following command from the project directory:

ant reinstall

(surely, this assumes you already have Apache Ant installed).That's it, after this command your application is installed and ready to run! Under the hood, ant uses build.xml file, generated by activitycreator. It creates bin/${ant.project.name}-debug.apk archive, signes it with debug key, which is enough to run application in the emulator, and installs it to the emulator device, using the command "adb install -r bin/${ant.project.name}-debug.apk".

Now back to our resource constraints. The emulator uses ~120 megs of RAM and ~5%-15% CPU. Other than that, my clear xfce4.4 + a couple of terminals use ~160 megs of RAM. So, this adds up to 280 megs of used RAM and ~20% used CPU, which leaves a plenty of resources for running a browser with lots of opened tabs.



0 коментарі

blog comments powered by Disqus