Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank GoogleMap on a real Android 2.3 device with Google API (Lv. 17)

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:

enter image description here

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.

like image 486
dumbfingers Avatar asked Mar 25 '13 13:03

dumbfingers


2 Answers

OK, after hours of hours of thinking and trying, I think I can mark this problem as fixed.

The problem is caused by the Wrong Date & Time in the 2.3 device.

The time and date on 2.3 device is reset to 2013/01/01 due to out of power for a long time(as you can see in the log output, it shows 01/04 as date). And that can also explain why running with the same code, the Google Maps V2 didn't show up on 2.3 device but will show up on 4.0+ device (because the 4.0+ device I'm using has the correct time).

I think because of the huge difference of date and time between this device and the Google Maps server, the communication between them got malfunctioned (don't know exactly why, but it should be some timestamp stuff).

When I manually set the date and time of the 2.3 device to the current time, the problem got solved immediately.

This problem is so weird and the logout just showing like:

Could not find class 'maps.i.k', referenced from method maps.z.ag.a

is so ambiguous that makes me very hard to think about the problem is caused by wrong date & time on the device.

So next time if you encountered something wrong while playing around with Google Maps API, please follow this steps to check:

  • Check if your devices' date & time settings correspond to your current time zone (Unfortunately the log output will not return much constructive information to lead you to think about the date & time)
  • Check if you've enabled the correct service in your API console (Enable Google Maps API Android V2 not Google Maps API V2, log will return Authentication Failed if you do something wrong with this step)
  • Check if you've used the correct keystore to get the API secret (The log will give you a hint saying Authentication Failed
  • Check if you've included the correct library files

Thanks for anyone who tried to help me, and I hope this question & solution can help others.

like image 126
dumbfingers Avatar answered Sep 28 '22 06:09

dumbfingers


This is the common problem occured in google Map using Api v2.The main reason in google play serviceis if the google play service is updated then only the mapview will display.The problem can be solved if you run the app in device.So better try in device it will work for you!!

like image 40
Janmejoy Avatar answered Sep 28 '22 06:09

Janmejoy