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,
antwon’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 targetsto 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.
Well, I’m certainly glad someone else dealt with this 2 weeks before I did.
Thanks for the help!
Yer welcome!
Thank you! It works for me!
Thanks!
Thank you much, worked like a charm.
FYI, i’m using Visual studio (2010) , so did the following things specifically
1. Android SDK Manager –> Verify Google Api’s in installed for Android 4.0.3 (API level 15)
2. Created a new Virtual Device (Google Api’s device – API level 15)
In Visual Studio –> Project –> Build –> Target 4.0.3 (this will ask for restart of the solution after close)
When restarted, worked like a charm.