David Janes' Code Weblog

November 13, 2009

18 Hours of JAR Hell with Android & Google Maps

android,tips · David Janes · 7:39 am ·

Yesterday, my experiments came with Android programming came to a crashing halt when I tried to use the Google Maps libraries. No matter what I tried – adding every possible Google Maps SDK, manually adding the jar to the project’s libs directory, a few more things too foolish to talk about – I would get one of these errors:

    [javac] .../LocationMapActivity.java:21: package com.google.android.maps does not exist
    [javac] import com.google.android.maps.*;
    [javac] ^
    [javac] .../LocationMapActivity.java:24: cannot find symbol
    [javac] symbol: class MapActivity
    [javac] 	extends MapActivity

or

W/dalvikvm(  247): Unable to resolve superclass of Lcom/.../LocationMapActivity; (89)
W/dalvikvm(  247): Link of class 'Lcom/.../LocationMapActivity;' failed
D/AndroidRuntime(  247): Shutting down VM
W/dalvikvm(  247): threadid=3: thread exiting with uncaught exception (group=0x4001b188)

or

Failure [INSTALL_FAILED_MISSING_SHARED_LIBRARY]

Well. Here’s what you need to know:

  • the emulator you’re running must match the target you set up your project for
  • the emulator actually (as I understand it) actually has a lot of code built into it, so it’s not enough to link against the jar file
  • if you don’t have the right target specified, ant won’t look for jar files and just give you the linking errors
  • the Google Maps SDK is tied into Android’s concept of a target

In particular, this is what you want to do to fix your problem – it’s all about “targets”:

  • run android list targets to find a suitable Google Maps-enabled target
  • make an avd (“Android Virtual Device”) that has that target. This is really easy to do in the UI provided by running android &. Don’t be fooled by seeing just “Platform” and “API Level” listed there – the target determines what these are
  • run the appropriate emulator to use the avd that you created, that has that target, that includes the Google Maps SDK: e.g. emulator -avd david_6 &
  • update your project to reflect the new target: android update project --path HelloAndroid --target 7

If you’re an Eclipse user, I’m sure there’s some easy way to do this, but the command line works just fine for me. I’m not the first person to see this problem, but I’ve never really seen this spelled out so explicitly how to solve it so hopefully you fine this of use.

3 comments »

  1. Well, I’m certainly glad someone else dealt with this 2 weeks before I did.

    Thanks for the help!

  2. David Janes · 2009-11-26 06:14

    Yer welcome!

  3. lucas · 2011-10-20 17:18

    Thank you! It works for me!

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Switch to our mobile site