Empty GoogleMap on a real Android 2.3 device with Google APIs (17)

Description of the question, please read this first

I am trying to get my simple application that will display the location of a user running on devices with Android 2.3 to Android 4.0+. The map does not appear on a real Android 2.3 device.

Currently, the application can run and display maps as I wanted on an Android 4.0+ device, without any problems.

Since it can display maps without any problems on Android 4.0+, therefore I believe that the problem should not be something wrong with the settings or permissions of Google Maps V2.

However, when I try to use it on Android 2.3 devices, the map area will be empty, as shown in the image below:

enter image description here

The application uses ActionBarSherlock, Google Maps API v2 and SupportMapFragment. The build targets SDK 17, min SDK 10.


Code snippet

I pasted and cut 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); } 

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; 

Log code 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) pointed to this line:

map.setOnMarkerDragListener (markerDragListener);

What i tried

And it is strange that if I add this line

 <uses-library android:name="com.google.android.maps" /> 

before AndroidManifest.xml , logcat will not show anything (without errors there is no warning), and the map is still empty. But someone has a message saying that this line solved the problem with an empty card: https://stackoverflow.com/questions/15595357/android-supportmapfragment-google-play-services-issue

In my Android Dependencies project folder Android Dependencies I have these *.jar :

 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 the response of this post , I know that Google Maps may not work well on the emulator. All I need to do is display the map on a real Android 2.3 device, which I failed.

In addition, I also paid close attention to these messages and tried their method (if applicable to my circumstances), but still does not please my problem:

Google Map V2 Map Link

How to use the Google Maps API v2 with API level 10?

Google MapFragment is empty (white) with Could not find class 'maps.j.k'

Using ActionBarSherlock with the new SupportMapFragment

If you need more information, leave a comment below and I will try to add them.

+6
source share
5 answers

Well, after several hours of reflection and trying, I think I can mark this problem as fixed.

The problem is caused by Incorrect date and time on the device 2.3.

The time and date on device 2.3 reset to 2013/01/01 due to insufficient power for a long time (as you can see in the output of the log, it shows 01/04 as a date). And this may also explain why it works with the same code that Google Maps V2 did not display on device 2.3, but will display on device 4.0+ (because the 4.0+ device that I use has the correct time).

I think because of the huge difference between the date and time between this device and the Google Maps server, the connection between them caused a failure (I donโ€™t know exactly why, but it should be some time).

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

This problem is so strange that the logout looks like this:

Could not find class 'maps.i.k' referenced by methods.z.ag.a

so ambiguous that itโ€™s very difficult for me to think about the problem caused by the wrong date and time on the device.

So, next time, if you encounter something wrong while playing with the Google Maps API, follow these steps to check:

  • Check if the date and time settings correspond to your devices with your current time zone (unfortunately, the output of the log will not return a lot of constructive information so that you can think about the date and time).
  • Check if the correct service is enabled in the 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)
  • Make sure you use the correct keystore to get the API secrecy (The log will give you an Authentication Failed hint
  • Make sure you include the correct library files.

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

+5
source

This is a common problem that occurs in google Map using Api v2 . The main reason in google play service is to update google play service , then only map display will be displayed. The problem can be solved if you run the application on the device. So itโ€™s better to try on the device, it will work for you!

+1
source

Check out this related question: Google Maps from scratch Android

It seems that changing from v1 to v2 makes it difficult to get a new API key, and in v2 the keys are stored in the manifest. Let me know if this works.

+1
source

OK I think the link below will help you with something, since it also saved me too, having the same problem. Although I'm not sure, since you have no problems with the API level 4.0+

google-maps-v2-shows-blank-screen-on-android-2-2

The problem may be due to Debug.keystore

Solution: Make sure that you are debugging your application with the same keystore with which you created your SHA-1 code to get yout API key.

let's say you use Ubantu and open your Eclipse as root, then whenever you create an application, eclipse will use default.keystore inside to launch your application on the device located in root/.android/debug.keystore , so when you create your API key, you have to make sure that you use the same Keystore with which you will create the application.

Hope this helps you.

+1
source

Add both permissions to the AndroidManifest.xml file:

 <permission android:name="YOUR_PACKAGE_NAME.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="YOUR_PACKAGE_NAME.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> 
+1
source

All Articles