Google maps not showing on android in release mode
Asked Answered
S

9

12

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!

Subdivide answered 5/3, 2013 at 8:55 Comment(3)
this may help #13697120Bookmark
Try generating your release key again: chocotech.blogspot.com/2012/10/…Churchwoman
https://mcmap.net/q/910650/-google-maps-api-key-in-release-build-doesn-39-t-workBrisket
S
14

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.

Shortly answered 16/2, 2017 at 12:11 Comment(3)
thanks ... i have been working 48 hours to solve this. no i got the solution.Nerveracking
@Tarciso. My debug apps are working fine. but release apk maps is not working. I have checked google_maps_api files well.. they all have updated key.. still not visible mapsSlackjawed
@GauravArora, did it showed something in console output ? had you checked in you google API Key if its enabled for production ?Shortly
L
11

in the map API V2, the ONLY thing that change between a release version and a debug version is the Key that you register here https://code.google.com/apis/console/

If debug is working and final release is not, it's the only change necessary.

So I suggest you to double check the hash code of your release keystore and make sure that it's properly input on the Google API Console.

Lyublin answered 5/3, 2013 at 9:47 Comment(2)
can it be that the signature algorithm should be SHA1withRSA rather than SHA256withRSA?Subdivide
Just to add an aspect to this very helpful answer. You can create an API key for both at once, debug and release key. Doing so you don't have to hassle with changes to the manifest or gradle config or so. Just use the one api key that works with all your app keys.Latif
R
3

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

Rhamnaceous answered 6/4, 2019 at 19:22 Comment(0)
E
1

I had the same problem... I've found the gogole_maps_api.xml file into the release/res/values folder... But inside the API_KEY was empty!!!!

After copying the API key also here, all works perfectly in debug mode and also in release!! Thanks Sumit Sinha for suggestionsenter image description here

Eximious answered 8/12, 2020 at 14:39 Comment(0)
S
1

I'm facing same problem, map work on debug but it's not working on Google Play Store

Try this:

I solved by add SHA1 key from Google play store to APIkey google maps console

or you can open this: https://github.com/react-native-maps/react-native-maps/issues/327

Sibilate answered 7/3, 2022 at 14:35 Comment(0)
P
0

Just clear data (Setting->App-select app-Clear data->uninstall) and try. this worked for me. Ensure that package name is same as that in google developer console. if you are created SHA1 code from custom keystore use the same in release mode. or generate apk by signing with that same keystore.

Plasmodium answered 12/5, 2015 at 9:58 Comment(0)
P
0

1- Create apk file using "Use the export Wizard" in "Android Manifest" file of your project.

2- After inserting key and before finishing, MD5 and SHA1 keys are shown as shown is this given pic-

3- Create new API Key for Android project for new SHA1 which is retrieved in point 2.

4- Use that API key in manifest file as shown below

5- Clean your project and build APK file again.

6- You can see google maps now in that apk.

Pileum answered 21/7, 2015 at 19:4 Comment(0)
W
0

I was following everything yet was not able to get it done, the thing I was doing wrong is that enter image description here

I was initially **checking ** both V1 and V2 signature versions.

Solution: Just check the V1 Signature

Washcloth answered 6/12, 2019 at 1:3 Comment(0)
P
-1

It's been a while, but I've found a very easy solution. Just set gradle like this:

buildTypes {
    release {
        isMinifyEnabled = false
        isShrinkResources = false
    }
}
Ply answered 3/2, 2022 at 14:2 Comment(1)
While this may solve the issue if any of your project classes / files that is crucial for showing the maps was removed by the obfuscation and minifying process. Doing this for release builds is not recommended.Sheets

© 2022 - 2024 — McMap. All rights reserved.