Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps not showing on android in release mode

I am trying to release my app, but having a problem with google maps. The app contains an activity (MapActivity) that displays a map. When running in debug mode, the map works fine. I signed my app in release mode, and got SHA1. I created a new android key on Google console as required (SHA1;packageName). Got the API Key

In my App, I referenced a copy of google-play-services-lib as required. I am using ADT.

map.xml

<?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.SupportMapFragment" />

MapActivity.java

public class MapActivity extends FragmentActivity {

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                        .getMap();
  }

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rentalcar"
android:versionCode="1"
android:versionName="1.0" >



<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<permission
      android:name="com.example.rentalcar.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.rentalcar.permission.MAPS_RECEIVE"/>


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

    <activity
        android:name="com.example.rentalcar.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter> 
    </activity>      

    <activity
        android:name="com.example.rentalcar.MapActivity"
        android:label="@string/title_activity_map"
        android:screenOrientation="portrait" >
    </activity>

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

</application>

</manifest>

The only weird thing is that when I use keytool to get SHA1 I get "Signature Algorithm name: SHA256withRSA. can this be the problem? If yes, how can I change it?

using keytool to get the certificate fingerprints

I am kind of stuck here! Thank you for any help!

like image 469
user1851212 Avatar asked Mar 05 '13 08:03

user1851212


People also ask

Why is Google Maps not displaying?

There are various reasons why this happens. It's possible the location accuracy option is disabled, you're using an older version of the app, or you don't have proper access to the internet. The Google Maps app itself may have issues, too. Cache files and other app data can sometimes cause various issues with the app.

Is Google Maps no longer on Android Auto?

Update to Android Auto makes Google Maps disappear Also owned by Google, Waze uses crowdsourced data to help it deliver the fastest and safest routes for users to follow. Unlike Google Maps, Waze concentrates on navigation although it can still lead you to gas stations and restaurants.

Why won't Google Maps open on my Android phone?

You may need to update your Google Maps app, connect to a stronger Wi-Fi signal, recalibrate the app, or check your location services. You can also reinstall the Google Maps app if it isn't working, or simply restart your iPhone or Android phone.


2 Answers

if you already tried @Budius answer and still facing this error, it might be caused by the following situation:

When you add your MapFragment, Android Studio create 2 files google_maps_api.xml: one inside src/debug/res/values folder and the other inside src/release/res/values.

But for some reason only the debug folder file is showed on Android Studio. So, when you change the APIkey value, it is done only at debug folder file.

So just copy the google_maps_api.xml file to release folder and assure that both are with same APIKey.

this worked for me after all other attempts.

like image 57
Tarciso Junior Avatar answered Sep 28 '22 11:09

Tarciso Junior


I was also facing the same problem since last few days and it took me around 2-3 days to figure out the problem. You need to add your API key at 2 places one in app/src/debug/res/values/google_maps_api.xml and other in app/src/release/res/values/google_maps_api.xml.

You can find the release/google_maps_api.xml in the project mode not in the Android/application mode.

You can check the pic here that where the release/google_maps_api.xml is available

like image 29
Sumit Sinha Avatar answered Sep 28 '22 12:09

Sumit Sinha