Published App on Play Store can't communicate with Google Maps API and Facebook API
Asked Answered
F

6

13

I created a signed APK with Android Studio, and I added to Google Developer console and Facebook console my SHA1 fingerprint and the relative api keys in my app. Everything works well if I upload my signed apk via USB, after installing it maps API and facebook api works well. If I upload the same apk to the Play Store, when I try to login with Facebook, it says "invalid key hash. The key hash blablabla doesn't match with any stored..". So if I log without facebook, I can't even get my google maps; this leads me to think that the apk loaded on the play store changes his fingerprint or some stuff like that. I checked all the stuff on Android Developers and Stackoverflow, but I can't make it work, because the strange thing is that this signed release apk works well until I load it on the Play Store.

Flock answered 21/6, 2017 at 9:16 Comment(3)
For Facebook you need a developer key hash and a release key hash. Take a look at this link: developers.facebook.com/docs/android/…Exhibitionism
look my answer for google map. You need to change SHA-1 which is generated by Google Play please find out new SHA-1 in your play console and upload it into your google map api and it works like a charm.Townsfolk
Are you using Firebase ?Morningglory
F
3

I finally solved, the problem was probably that the file google_maps_api.xml provided by the api was not loaded in the release, so i

i did like that:

buildTypes {
    debug {
        manifestPlaceholders = [mapsKey: "AIzaSyB8o9KzQ5YN8U8AFS************"]
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        manifestPlaceholders = [mapsKey: "AIzaSyApLacqgkdIR7uEpcf*****************"]
    }
}

and then in my AndroidManifest

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="${mapsKey}" />

Reference: https://mcmap.net/q/473642/-multiple-api-keys-for-single-android-studio-project

then i registered 2 different keys each with the right sha1 fingerprint, one debug and the other given by Google Play console (not the upload certificate, but the other one generated by Google).

Very Very thanks to Zuhad and Andy Developer for inspiration.

Flock answered 21/6, 2017 at 13:38 Comment(0)
R
31

With inspiration from @Andy Developer, I could display the map after my app was uploaded to Google Play. These were the steps:

  1. Upload your app to Google Play (signed APK file)
  2. After the app has been submitted and approved, select your app from Google Play Console
  3. Go to Development Tools -> Release management -> App signing

App Signing in Google Play Console

  1. Copy the first SHA-1 certificate which Google Play has issued after uploading the app.
  2. Go to Google Console and select your project.
  3. Select your API-key, restrict your key, and paste the SHA-1 after package name.

Paste SHA-1 into Google Console

  1. Press Save, wait a couple of mins. and your app should show Google Maps.
Rennet answered 11/8, 2017 at 20:42 Comment(0)
T
29

Here is the answer for why you can't see the Google Map.

I recently Upload the APK on Google Play store and I faced the same issue after checking the Play Console I found the solution for this problem.

Their is no problem with your key but the problem is with your SHA-1. You signed your APK with your SHA-1 that is fine and then upload the APK it also fine.

But as per the new update for Play Console when you signed your APK with SHA-1 and upload the APK it only signed by you but as per the new update it is also signed by Google Play for more security. Have a look here some part of Google Play section:

With Google Play App Signing: You sign your app with your upload key. Then, Google verifies and removes the upload key signature. Finally, Google re-signs the app with the original app signing key you provided and delivers your app to the user.

You can refer Documentation here.

Now, The Answer of your question is After successfully upload the APK you can see that in the section with Two SHA-1 the 1st SHA-1 is Google created its own and 2nd SHA-1 is its yours.

So just copy the Google SHA-1 and paste it to your console where you generate the Google Map API Key.

Townsfolk answered 21/6, 2017 at 9:47 Comment(6)
Thanks man ! I was breaking my head for 3 days trying to figure this out. Although there were a ton of answers out there asking to change the sha1 key, this was crisp and clear and to the point. Thanks for your help.Acrefoot
@AndyDeveloper Thanks man...really you saved me. I have literally delete my project from Firebase and Google Console and recreate it & configure it again but that doesn't make any difference. Heats Off To Your answer.Splashdown
@AndyDeveloper it helps me a lots, Thank you.Raffia
I must say, you saved my life :DTerritus
Can you point me where I can find this Google SHA-1? Is it on the Google Console?Giotto
you are my hero :)Tol
F
3

I finally solved, the problem was probably that the file google_maps_api.xml provided by the api was not loaded in the release, so i

i did like that:

buildTypes {
    debug {
        manifestPlaceholders = [mapsKey: "AIzaSyB8o9KzQ5YN8U8AFS************"]
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        manifestPlaceholders = [mapsKey: "AIzaSyApLacqgkdIR7uEpcf*****************"]
    }
}

and then in my AndroidManifest

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="${mapsKey}" />

Reference: https://mcmap.net/q/473642/-multiple-api-keys-for-single-android-studio-project

then i registered 2 different keys each with the right sha1 fingerprint, one debug and the other given by Google Play console (not the upload certificate, but the other one generated by Google).

Very Very thanks to Zuhad and Andy Developer for inspiration.

Flock answered 21/6, 2017 at 13:38 Comment(0)
A
0

The debug and release build types of your application are signed with two different keys.

You need to register both keys in the Google Maps and Facebook for them to allow access to their services

Anthropogeography answered 21/6, 2017 at 9:33 Comment(3)
That's what I did. I also downloaded from play store console the deployment cert and I executed the following command cat deployment_cert.der |openssl sha1 -binary | openssl base64 and it gave me the api key for Facebook login that now works, but i can't make Maps work. In the file under /app/src/release/res/values/google_maps_api.xml I added the key provided from Maps console, in which i also registered the sha1 fingerprint from my own certificate (generated from android studio) and the sha1 fingerprint from play store console, but it doesn't workFlock
Is your debug build using a different applicationId/package than the release build ? Depending on this you might have to add another entry on the Google maps API key configAnthropogeography
am generating debug api key its working.when i integrate signedapi key for publishing its nor working please help me.after generating signes apk and once again generate signed google maps api key with signed keystore file and alias.Grizel
S
0

Yes , Obviously the map will not load in signed APK.

Solution:

When you generate API key in Google API console you need to restrict the key with SHA key

But After generating Signed APk you need to take release mode SHA key and add in API console for the APIenter image description here

I have attached Image, Have a look

hope it helps.

Stephanestephani answered 21/6, 2017 at 9:36 Comment(3)
the thing is that the api keys for debug and release are different, in fact I wrote in the gradle file buildTypes { debug { manifestPlaceholders = [google_map_key: "AIzaSyB8o9KzQ5YN8U8AFSxbTJLheFiubF****"] } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' manifestPlaceholders = [google_map_key: "AIzaSyApLacqgkdIR7uEpcf7EDuGvsQlgh*****"] signingConfig signingConfigs.config }Flock
even if i add like you said for every key both debug sha1 and release sha1 it doesn't workFlock
Better create a new API key and try to implement, Only the API key is the solution I hopeStephanestephani
S
0

For Facebook to generate hash key use the below code:

try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "YOUR PACKAGE NAME",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

Once you receive the hashcode, do paste the same in Facebook developer console and move ahead

hope it helps:)

Stephanestephani answered 21/6, 2017 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.