Question Description, Please read this first
I am trying to get my simple app which will display user's location running on devices from Android 2.3 to Android 4.0+ devices. The map does not show up on a real Android 2.3 device.
The app currently can run and show maps as I desired on Android 4.0+ device without any problem.
Because it can display maps without any problem on Android 4.0+, so I presume the problem should not be anything wrong with the settings or permissions of Google Maps V2.
However when I try it on Android 2.3 devices, the map area will be a blank like the screen shot shown below:
The app uses ActionBarSherlock, Google Maps API v2 and SupportMapFragment. Build targeted to SDK 17, min SDK 10.
Code Snippet
I pasted and trimmed the code to show the only related part, please leave a comment if you need anything else.
activity_layout.xml
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/incident_padding_right" />
Activity.java
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.SupportMapFragment;
public class Activity extends SherlockFragmentActivity{
private static GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_layout);
............
//Set up map view
map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
............
OnMarkerDragListener markerDragListener = new OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker marker) {
// Called when the marker drag is started
}
@Override
public void onMarkerDragEnd(Marker marker) {
// Called when the marker is dropped down.
coords[0] = marker.getPosition().latitude;
coords[1] = marker.getPosition().longitude;
RestoreUIwithSavedLocation(coords);
Log.d(TAG, "Pin Dropped at: " + coords[0] + ", " + coords[1]);
}
@Override
public void onMarkerDrag(Marker marker) {
}
};
map.setOnMarkerDragListener(markerDragListener);
}
The Logcat when running on a real Android 2.3 device:
01-04 21:16:52.020: D/dalvikvm(19074): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
01-04 21:16:52.150: W/dalvikvm(19074): Unable to resolve superclass of Lmaps/p/s; (427)
01-04 21:16:52.150: W/dalvikvm(19074): Link of class 'Lmaps/p/s;' failed
01-04 21:16:52.150: W/dalvikvm(19074): Unable to resolve superclass of Lmaps/y/bo; (3820)
01-04 21:16:52.150: W/dalvikvm(19074): Link of class 'Lmaps/y/bo;' failed
01-04 21:16:52.150: W/dalvikvm(19074): Unable to resolve superclass of Lmaps/i/k; (4208)
01-04 21:16:52.150: W/dalvikvm(19074): Link of class 'Lmaps/i/k;' failed
01-04 21:16:52.150: E/dalvikvm(19074): Could not find class 'maps.i.k', referenced from method maps.z.ag.a
01-04 21:16:52.150: W/dalvikvm(19074): VFY: unable to resolve new-instance 3540 (Lmaps/i/k;) in Lmaps/z/ag;
01-04 21:16:52.150: D/dalvikvm(19074): VFY: replacing opcode 0x22 at 0x006d
01-04 21:16:52.160: D/dalvikvm(19074): VFY: dead code 0x006f-007f in Lmaps/z/ag;.a (Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;ZLjava/lang/String;)Lmaps/z/ag;
The logcat when running on emulator with Google API Lv.10
03-25 13:00:47.974: W/GooglePlayServicesUtil(751): Google Play services is missing.
03-25 13:00:47.992: W/GooglePlayServicesUtil(751): Google Play services is missing.
03-25 13:00:47.992: W/GooglePlayServicesUtil(751): Google Play services is missing.
03-25 13:00:48.002: W/GooglePlayServicesUtil(751): Google Play services is missing.
03-25 13:00:48.002: W/GooglePlayServicesUtil(751): Google Play services is missing.
03-25 13:00:48.022: W/GooglePlayServicesUtil(751): Google Play services is missing.
03-25 13:00:48.072: D/AndroidRuntime(751): Shutting down VM
03-25 13:00:48.072: W/dalvikvm(751): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-25 13:00:48.133: E/AndroidRuntime(751): FATAL EXCEPTION: main
03-25 13:00:48.133: E/AndroidRuntime(751): java.lang.RuntimeException: Unable to start activity ComponentInfo{Activity}: java.lang.NullPointerException
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.os.Looper.loop(Looper.java:130)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-25 13:00:48.133: E/AndroidRuntime(751): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 13:00:48.133: E/AndroidRuntime(751): at java.lang.reflect.Method.invoke(Method.java:507)
03-25 13:00:48.133: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-25 13:00:48.133: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-25 13:00:48.133: E/AndroidRuntime(751): at dalvik.system.NativeStart.main(Native Method)
03-25 13:00:48.133: E/AndroidRuntime(751): Caused by: java.lang.NullPointerException
03-25 13:00:48.133: E/AndroidRuntime(751): at Activity.onCreate(Activity.java:250)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 13:00:48.133: E/AndroidRuntime(751): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-25 13:00:48.133: E/AndroidRuntime(751): ... 11 more
Activity.onCreate(Activity.java:250)
is pointed to this line:
map.setOnMarkerDragListener(markerDragListener);
What I Have Tried
And its strange that if I add this line
<uses-library android:name="com.google.android.maps" />
to AndroidManifest.xml
, the logcat will show nothing (no error no warning), and the map is still blank. But someone has a post saying that this line solved her/his blank map issue: https://stackoverflow.com/questions/15595357/android-supportmapfragment-google-play-services-issue
In my project's Android Dependencies
folder, I've got these *.jar
files:
actionbar-sherlock-4.2-library.jar
google-play-services_lib.jar
android-support-v4.jar
actionbarsherlock-plugin-maps-4.2.0.jar
google-play-services.jar
From an answer of this post, I am aware that the Google Maps may not running well on emulator. All I need is to make the map displayed on a real Android 2.3 device which I failed.
In addition, I've also paid close attention to these post and tried their method (if applicable to my circumstances) but still no joy on my issue:
Google Map V2 android map referencing
How to use Google Maps API v2 with API level 10?
Google MapFragment is blank (white) with Could not find class 'maps.j.k'
Using ActionBarSherlock With the New SupportMapFragment
If you need more information, please leave a comment below and I'll try to add them.