Getting Rid of Android’s ApiDemos Eclipse Warnings

Google’s ApiDemos sample code is great. It gives you everything you need. Unless you’ve already configured your Eclipse environment, you may get a ton of Warnings when you add the ApiDemos sample app to your workspace. Here’s how to get rid of those annoying warnings.

Note that you don’t have to get rid of the Warnings. The ApiDemos app will build and run perfectly fine. This is purely for getting rid of the annoyances.

Adding the ApiDemos App to Your Workspace

This section should be fairly straight-forward.

  1. Either right-click in the Package Explorer or go to File->New and choose Other or Android Project if it’s available.
  2. Pick the Build Target first.
  3. Select Create project from existing sample and choose ApiDemos from the list (if it’s not already selected.)
  4. Make any changes you want to the Project Name or Application Name, such as renaming it to ApiDemos 1.6 or 2.1 etc.
  5. Click Finish

The Warnings

Your beautiful Problems view will now have these monstrosities.
alt text

Getting Rid of it Forever or Per Project?

Decision time. You can either change the global Eclipse settings or do this on a per-project basis. I’m going to show you both ways, and you’re more than welcome to do it whichever way you want.

Making the Changes

Getting Ready

For per-project: you right-click on the project and choose Properties.
Per-Project Setup

For global Eclipse, you go to:
Windows: Window -> Preferences
Mac OSX: Eclipse -> Preferences
Global Preferences

The next steps will be the same for both methods.
Go to Java -> Compiler -> Errors/Warnings

Time to make the changes. For the per-project option, you will need to check off the box “Enable project specific settings“. Also note that you can jump to the Global option by clicking the Configure Workspace Settings… link.

Similarly, you can jump to a Project Specific by clicking on the link

The Changes

  1. Code style – change the Non-static access to static memberWarning to Ignore.

  2. Potential programming problems – change the Dead code (e.g. ‘if (false)’): from Warning to Ignore.

  3. Unnecessary code – Change:
    • Local variable is never read:
    • Parameter is never read:
    • Unused import:
    • Unused local or private member:

    from Warning to Ignore

  4. Generic types – Change:
    • Unchecked generic type operation:
    • Usage of raw type:

    From Warning to Ignore

  5. Deprecated and restricted API – Change Deprecated API: from Warning to Ignore

Tada!

Now your Problems view is nice and clean again! Yay! Hope this helped those who ran into the warnings.

  • http://firemanworld.wordpress.com/ David

    Well, that's a nice piece of advise. Nevertheless, I guess a company like Google, that is meant to be creating great software and having the best software engineers, could at least put demos where they show how good they do it, right?

    The current API version, running for Android 2.1 gives my 326 warnings. Some of them are about code that is dead (i.e. never gets executed) I don't think this gives a nice image.