Google Places for Android API key does not work on app from Play Store

前端 未结 5 2164
感情败类
感情败类 2021-01-11 10:38

I recently launched an Android app which makes use of the Google Places autocomplete widget/API. As part of the configuration for this, I added the API key to my Android\'s

5条回答
  •  粉色の甜心
    2021-01-11 11:08

    The answer by @NullPointer is functionally correct, and does indeed fix my problem. But to give a more direct answer to my own question, the root cause of the problem has to do with substantially different procedures for configuring Google APIs for a local debug version of an Android app and a release version of the same app.

    Part of the confusion here has to do with the Google console itself which says:

    Then use the following command to get the (SHA-1) fingerprint:

    keytool -list -v -keystore mystore.keystore
    

    When building and testing an app locally, in debug mode, in fact running keytool against the debug keystore file, and pasting the SHA-1 hash into the Google console will get the API to work. After sitting on a codebase for several months, or longer, and the APIs appearing to be very stable, it then comes as a surprise what happens next when repeating these steps with the release APK.

    It is a surprise, because following the same steps won't work for the release app. This is because the Google Play Store actually resigns your APK with a different key, which therefore has a different SHA-1 hash. To find the SHA-1 hash which needs to be used, one may visit Release management -> App signing in the Google Play console. Do this after publishing your app and waiting perhaps 10-15 minutes for it to refresh. Then, just paste this SHA-1 back into the Google API console, and off you go.

    By the way, my question is very similar to Published App on Play Store can't communicate with Google Maps API and Facebook API, though not much emphasis was given there for why a Google API might be working in debug mode, but not on the Play Store. Incidentally, I give credit to @RohitChauhan who pasted a comment containing a link to this question.

提交回复
热议问题