Monday, April 30, 2012

Adding Libraries to your Android project with ADT 17

The developers over at Google like to change things up with each ADT version, it seems. For those unaware, the ADT (Android Developer Tools) is simply the plugin that goes along with Eclipse. It does all the heavy lifting of compilation (with the Android SDK) for Android projects. Although things are getting more stable with each new version, there are always a few gotchas in each version. The latest version is no different.

In the latest ADT version, you may have seen some unusual runtime crashes after compilation. These crashes come with the error that looks something like “method or object XXX wasn’t found”. When I first saw this crash, I thought something like that would have been caught during compile time. It is really strange to see this crash during the running of the application.

After a bit of poking around on Google’s site, and checking out Stack Exchange like usual, I found a few interesting pages that point to the problem. I eventually found my way to Foxykeep’s article on the latest Android ADT plugin.

The gotcha in this ADT version has to do with how libraries are linked into the APK. Before this version, I would link standard Jar files to a project by going to Properties->Build Paths and then I would add the external Jar there. In ADT 17, this method doesn’t quite work, although you won’t see any compile time errors from Eclipse about it!

Now, instead of the above method, you actually need to add your external libraries to a new source file in your project called “libs”. Any Jar files located in this file will be recognized by the ADT and will be handled appropriately.

Hats off to Foxykeep for finding the right solution. This one is a tough solution to track down.

Monday, April 23, 2012

Does your App Support Android 4.0? Think Again.

Think your app supports Android 4.0 just because you support 2.2 or 2.3? Maybe not. If your app uses a few common Java classes, you may want to double check your app on several 4.0 devices.

Probably like most developers, when we saw Ice Cream Sandwich release, we didn’t have any thoughts that our app may not work properly. All the changes seemed to be more closely related to the UI, not the heart of the framework.

A few months ago, we noticed a handful of reviews popping up on the market mentioning total failures and really strange behavior. On some of the reviews, we got the lucky tip of a Nexus S being used, as well as other potential 4.0 devices like the Motorola Zoom. These strange reviews prompted us to go out and grab several 4.0 devices just to see what was going on.

It turns out, the mass majority of our web calls were being kicked back from the server with strange errors about Post requests being sent instead of Get requests.

After a bit of research, I discovered Stack Overflow comes to the rescue as usual ( one and two). In short, the problem has to do with a update to the HttpURLConnection class. Specifically, the setDoOutput method has been changed (it actually works now). A quick review of the HttpURLConnection documents show a few new updates that really should be reviewed by anyone who is using it.

So with the above changes in mind, it’s a really good idea to check your app versus any new versions coming out. There’s really no way to find this landmine without actually using the app on an Ice Cream Sandwich device. Always remember that the more Android specific APIs are not the only classes are modified by Google. The Android team has free reign to change any other aspect they see fit.