Android from scratch

January 18, 2010

Attaching Android platform source in Eclipse

Are you tired of seeing this when you look at your platform JAR in Eclipse?

Dude, where's my source?

(more…)

December 23, 2009

Emulator frustrations for n00bs

Here are a hodgepodge of issues related to using the emulator.

The emulator takes forever to come up

Yes, yes it does, especially the first time you start it. It’s emulating booting up a complete OS running on a different architecture (ARM processor) than your development machine – so yeah, it’s a little slow. If you have an Android device you know that even running natively it’s not exactly an instant startup, so expect some delays in the emulator too.

Just go ahead and start the emulator when you start Eclipse and it’ll be there when you need it. Keep it running, there’s no need to stop and start it all the time.

Why does deploying a package to the emulator keep failing?

Often this is because you’re trying to deploy before the emulator has finished booting (because you waited until you were ready to try out your app before starting the emulator). The Home process needs to be running before a deploy will work. It’s a common n00b mistake to try the “run” button on Eclipse, watch it start an emulator and fail to deploy, kill the emulator, and try it again – it will never succeed until the emulator finishes booting.

Deploy may also fail for basically the same reason when the device bridge server has failed (see below) and Eclipse DDMS starts a new emulator (or tries to).

Of course, the other reason deploying may fail is if there’s something wrong with your package. Perhaps the API you’re developing against isn’t available on the emulator, or you’ve messed up something in the application manifest. But those problems should be fairly easy to diagnose from the error messages on the console.

I keep ending up with emulators that can’t be attached to

I’m not sure why this happens – something to do with networking (esp. during suspend/hibernate), or non-Sun Java JDK, or updating components while an emulator is running. But sometimes you’ll be running an emulator and it won’t show up in the list of emulators (either the command line adb devices or in the Eclipse DDMS perspective – or I’ve seen it show up in the perspective but without any processes).

Of course the simple remedy is to kill the emulator and start a new one, but as noted previously, that takes forever. The emulator is  running – why can’t you connect to it?

Try using the “Reset adb” option from the DDMS Devices view menu, or restarting the server at the command line:

adb kill-server
adb start-server

Otherwise I don’t know what you can do. I have a question in about this and I’m waiting for an answer, too.

My emulator keeps offering to “force close” odd things, especially at startup

This is pretty common for me at least; you may never have seen it if you have better hardware. Just choose the “wait” option, everything will work out. I have a theory about this – perhaps someone who knows better will enlighten me if I’m wrong. Android has a policy of offering to force close non-responsive elements, where “non-responsive” means it hasn’t handled an event five seconds after it was notified of the event. As noted above, you’re running an emulator here, and it tends to run a bit slowly – but the clock is still ticking in realtime. I believe it’s simply a matter of certain parts of the operating system taking too long to respond, especially at boot time. Just ignore it and wait for them to finish.

December 22, 2009

What’s with the various API levels and types in the SDK?

Filed under: SDK level 2.0.1, n00b frustrations — Tags: , , , , — luke @ 2:59 pm

(As of SDK 2.0.1)

The API levels 1.0 through 2.0.1 are versions of the framework with which you develop Android applications (see http://developer.android.com/guide/appendix/api-levels.html for more). They’re fairly backward compatible but not completely. These are also referred to by integer API numbers and sometimes names:

  • 1 = version 1.0
  • 2 = version 1.1
  • 3 = version 1.5 (Cupcake)
  • 4 = version 1.6 (Donut)
  • 5 = version 2.0 (Eclair)
  • 6 = version 2.0.1

various_apis

The devices out there may be one of several different versions. At the time of writing, my stock T-Mobile G1 is at 1.6 (and may never get 2.0 as evidently the memory requirements are prohibitive). The Droid runs 2.0. I seem to recall hearing of another phone that was still stuck on 1.5 (the Cliq?). If you want to know the relative percentages of what’s out there, check the Platform Versions Dashboard.

When you develop an application, you have to specify what API level you’re developing for. Then the device will know whether it can support your application. For the widest support you’ll want the earliest feasible API (probably 1.5 for now), but then you’re missing out on the features of later APIs.

When you’re selecting the “target” for creating an emulator or developing an app, you also have a choice of developing against the Google APIs or not. These add more libraries for your application to use – currently, this is basically just if you want to integrate Google Maps into your application; later versions of the API may have other useful libraries. The language of “Google API” is a bit confusing when added to SDK/Android API versioning. It’s added functionality on top of the standard Android platform – each “Google APIs” target also includes the API platform with the number given.

December 9, 2009

Creating your own emulator skins

Filed under: Shiny Objects, emulator — Tags: , , — daeron @ 1:57 am

One of the first things a software developer does when beginning to work with a new IDE or tool set is to look for ways to customize their environment, either to better fit the way they work or to match their sense of style. For example, I always prefer my code editor to display primarily green text on a black background (black on white just hurts my eyes!).  Development with the Android SDK offers both customization of the IDE (eclipse settings) as well as customization of the emulator with the use of “skins”.

Each version of the android platform comes with several default skins which you can find located in the directories under <android-sdk-base-directory>/platforms/android-X.X/skins. An android skin consists of a single  layout file referencing a number of image files.

One particular skin that caught my eye was the platform-1.5/HVGA skin which looked most similar to the android-based phones I was looking at. However, not content with the drab maroon/red color scheme I decided to load up the main device background image in “The Gimp” image editing tool to add some zip. The results are shown below – a basic “leather” phone and “camo” style for military enthusiasts.

Sample Skins created for Android Emulator with The Gimp

Sample Skins created for Android Emulator with The Gimp

I’ve made these two skins freely available for download in a zip file at the bottom of this post. Also included in the zip file is a gimp format file (device.xcf) if you’re familiar with the tool and would like to try overlaying your own textures using the “mask” layer. To use these skins, simply unzip the file into the skins directory of the platform(s) you are targeting.

Custom skins extracted under the "skins" directory

The next step is to open the Android SDK and AVD manager, delete your existing Android Virtual Device, and add a new device for the platform and skin you wish to use:

Create New AVD

Here is one other site I found with skins more closely matching real phones if you’d like to try them as well. Enjoy!

Android Skins (downloadable .zip file)

Powered by WordPress