2

Google maps was working on a published app and now for some reason it has just stopped displaying the map. Here is the manifest:

<manifest 

.....

<permission
    android:name="com.x.x.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.x.x.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">

    .....

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/map_key" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="4030500" />

</application>

I have got the debug and release SHA-1 keys from the debug and release store and put them on the Google Maps Android API V2 and have put the API key in to the manifest (hardcoded and in strings.xml).

Here is the layout:

<fragment 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

Here is the how I try to access the SupportMapFragment from the fragment being displayed:

    private void setUpMapIfNeeded() 
{
        SupportMapFragment fragment = (SupportMapFragment)fManager.findFragmentById(R.id.map);
        if (fragment != null) 
        {
            mMap = fragment.getMap();
        }

        // Check if we were successful in obtaining the map.
        if (mMap != null)
            setUpMap();
}

However fragment always returns null. At one point I was getting the failed to Authorise message, but currently I dont see that. Only a blank map.

Update: It does not seem to be a problem with the keys, it is to do with

  android:name="com.google.android.gms.maps.SupportMapFragment"

in the layout file. When I try to get the fragment by id it returns null. The frustrating thing is that I have created a test project where the set up is basically identical and it works. Yet when I try the same code in this project it is not working. Both projects are pointing at the same Google Play Services library project and they both point to the Support Library v4. Even the manifest has the same entries. Also, if I replace SupportMapFragment with MapFragment it works ok.

Clive Jefferies
  • 1,138
  • 14
  • 26

5 Answers5

3

if everything is the same (you dont change the package name, or the key, and you are using the debug sha1 for the debug api key, ),and it stoped working, i would say that you have a conflict with the version of play services. try removing the hardcoded version here

 <meta-data
            android:name="com.google.android.gms.version"
            android:value="4030500" />

probably that version is not working with your google play services version (you can chek the actual version in google-play-services_lib>res>values>version.xml). check that the jar you are using is exactly that version, and change it if its not. Also, if you check the log cat, you can see something like

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.

i would change that meta-data to

<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />

that is what google recommends and also follow the other advises int that page

anyways, if you take a look at logcat (or post it here) probably we can get a clue on the logs around setUpMapIfNeeded()

Carlos Robles
  • 10,828
  • 3
  • 41
  • 60
  • I feel you answer is useful and I upvoted it to balance this unfairness. – Ernir Erlingsson Jan 08 '14 at 18:53
  • Thanks Carlos, I made the change, but it has not helped. I have looked on Logcat and there is nothing there. That is why I am struggling with this. I am going to create a brand new project to see if it is key related or code related. – Clive Jefferies Jan 09 '14 at 09:50
  • Probably it cannot find the classMapSupportFragment. So you say that in the new project it is working?? Probably you can compare the properties > android > build path (all the tabs) to check if there is something (like support library, play services librsry) that is not correctly referenced or exported. Or you can copy everything to the new project :/ – Carlos Robles Jan 09 '14 at 12:10
  • Anyways I could be great if we can take a look at the logcat even if there is not error, probably somebody can see any identificable pattern – Carlos Robles Jan 09 '14 at 12:12
  • The thing is that my class extends MapSupportFragment and that is working, yet it cannot seem to find it from the XML. In the new project it is pointing to the same Google Play Services library project and its own support v4. Also the, attributes in the manifest are the same. In logcat there is literally no output. – Clive Jefferies Jan 09 '14 at 15:04
0

I'm not sure why it stopped working when it had worked previously, but this was the solution:

SupportMapFragment - Binary xml file line #2: Error inflating class fragment

Community
  • 1
  • 1
Clive Jefferies
  • 1,138
  • 14
  • 26
0

Well according to the GoogleMap Android API setup, it says

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/>

which is what I did and works. I've not used suppotMapFragment myself but from this link here, the element seems to be

<fragment
      class="com.google.android.gms.maps.SupportMapFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
Daniel Wong
  • 147
  • 2
  • 10
0

You probably checked most of the things already (as I did). My map worked perfectly with the debug keystore, but went blank when I switched to the signed key. My problem was solved when I created an Api Key (with debug key+project package name) in one google account to use during development time.... and I created another Signed Api Key (signed keystore+project package name) on another google account. Apparently you cannot have more than one API key for the same package name (even if the keystore is different!) on the same google account.

Josh
  • 6,251
  • 2
  • 46
  • 73
0

This can be the cause of your SHA1 certificate changing, what you have to do is get the new SHA1 and edit it in your Google Console where you get the Maps API, then try to regenerate a new API and give it like 5 minutes to work properly.

Yonatan Dawit
  • 589
  • 7
  • 11