Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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()

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"/>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top