Friday, February 10, 2012

How to Quickly Support Ice Cream Sandwich

Android 4.0 (Ice Cream Sandwich) has been released for a few months now and a lot of apps still don't support it. A quick look at the Platform Versions page reveals only about 5% have Honeycomb or ICS at this time. While that may not be a lot, there's an interesting trend where users with newer versions of Android download more apps.

I personally am in the process of updating all of my apps to ICS and for the most part it's pretty simple. Below are some steps to quickly get the most benefits of ICS in the shortest time possible.

Download the Latest SDKs and Developer Tools
The first thing your should do is make sure your IDE and SDKs are up-to-date.
  1. Open Eclipse
  2. Help > Check for Updates (If ADT has an update install it.)
  3. Window > Android SDK Manager
  4. Check all the newest SDKs and new Android Tools and download them. Screenshot below shows 4.0.3.
Android SDK Manager with 4.0.3 and the latest SDK tools installed. 

Update the Project SDK
  1. Right click the Project folder name in Eclipse and select Properties.
  2. Go to the Android section and check the latest version. This gives you access to the latest APIs. Don't worry you can still target older versions.

Project Properties, Android 4.0.3 selected.
Tip: If you start using the new APIs you'll need to make sure that you don't call them while running on older versions of Android. A great way to do this is to temporarily switch the target SDK version in the project settings to the lowest version. Then check to see if any of the compile errors can be hit on those versions.

Set the Target Versions in the AndroidManifest.xml
Open the AndroidManifest.xml and change the uses-sdk tag to match the version of the SDK you selected. Android 4.0.3 has an API level of 15. The example below shows an app that supports 4.0.3 down to Android 1.6, API level 4.

Changing the sdkTargetVersion to 14 or higher will take you out of compatibility mode. This means certain key features will be turned on. Like the Action Bar replacing the menu button.

Consider Dropping Older Versions
Likewise holding on to older version can be a drag. At this time Android 2.1 is a good minimum version to support for maximum coverage (98%). Supporting Android 2.2 (90%)  as the minimum version is also acceptable too.

Enable Hardware Accelerated Rendering
Android 3.0 introduced hardware accelerated rendering. While this won't make your apps faster, it will make animations smoother. Do this at the application level in the manifest.

Hardware accelerated rendering is awesome but it does have its drawbacks. This is one thing to consider while testing your app. Certain features require more memory or actually draw slower when using 2D-accelerated drawing. If this is the case, you can disable hardware acceleration at the application, activity, and view levels. Check out this article for more information.

Use the New Themes
In general, it's a good idea to have a theme associated with your app even if it's just an alias to the stock theme. This gives you the ability to make minor tweaks to the look and feel. Android 3.0 introduced the Holographic theme, (@android:style/Theme.Holo) This is the standard Android theme going forward and it is a requirement for anyone that has the Android Market to have this theme on their device. To enable it create these XML files.
res/values/themes.xml

  
res/values-v11/themes.xml

  
AndroidManifest.xml

De-Lint your App
The latest release of the ADT introduced Eclipse integration with the android lint tool. This tool is nice for finding bugs and bad practices with your app. A few things it finds is unused resources, over draw performance issues, and even edge case bugs that cause weird crashes on some phones.

To run the tool right click on the Project Folder > Android Tools > Run Lint: Check for Common Errors menu.

The issues will appear as warnings some as errors. Fix the ones of importance. I'd give higher priority over possible crash and performance bugs.

Fix JNI References
This isn't for most developers but if you write native code check out this article. Essentially, Dalvik moves objects around if you're running with a targetSdkVersion="14" or higher. The goal is to improve memory usage. CheckJNI is a tool that has been out for a while that finds bad practices that can cause crashes in ICS. This is a painful process that you'll need to do eventually. Unless you always stuck to the best practices.

Apart from the JNI References, following these steps is the fast track way to support ICS. It should probably take 1-3 days' worth of work to get an ICS apk ready for the market. While most of your user base won't get these enhancements the most important share of your users will. Lastly, don't upload the apk until you've tested it on the versions you support and you feel like it meets the level of quality you want.

2 comments:

  1. You can also use bugsense to capture or the errors that will inevitably make it into the release

    ReplyDelete
  2. hi..Im college student, thanks for sharing :)

    ReplyDelete