0

I've been using Google Maps API in debug mode and working fine all along until it's in Release mode. Correct me if I'm wrong, we need a separated API key for Google Maps if we wished to release our app.

enter image description here

I've done the following:

  • Created new API key
  • enabled billing account in my project at GCP

In order to extract the SHA-1 key, I've navigated to project/android/app where I can see myapp.keystore and run the command keytool -list -v -keystore mypp.keystore.

After created the API_KEY, I've navigated to project/android/app/src/main/AndroidManifest.xml and modify the key

  <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="xxxxxx"/>

What else could've been missing? Thanks in advance

Please notice that this is a React-Native project and there isn't a separated Release and Debug directory/path to configure the APIKEY

Isaac
  • 12,042
  • 16
  • 52
  • 116

2 Answers2

0

There should be separated keys for DEBUG and RELEASE versions. If you create Google Maps Activity in Android Studio it will create separated resource files google_maps_api.xml with API_KEY value. As you can see debug and realease versions has different SHA-1 certificate fingerprint, what means theirs keys shouldn't be same.

Of course, It means that mentioned code in manifest should be changed to resources reference.

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key"/>

And key files should be at followed directories:

src/debug/res/values/google_maps_api.xml

src/release/res/values/google_maps_api.xml

Ircover
  • 2,406
  • 2
  • 22
  • 42
  • Many thanks for trying to help out. I understand your point but lets say I'm just trying to make it work for release minimally. I've use the `RELEASE` version's `SHA-1 certificate fingerprint` to create a new API_KEY, so isn't that enough? – Isaac Sep 20 '18 at 10:48
  • You said maps working in debug mode. It means your key is created for debug. Or are you saying you already created release key and it doesn't work? – Ircover Sep 20 '18 at 10:54
  • During development period the map was working. Now that I'm focusing just on releasing the app, I've not tested this new key with debug mode – Isaac Sep 20 '18 at 10:57
  • Main point is to use debug key in debug version and release key in release version. I added to my answer directories for resource files, so if you still don't have them you can create. – Ircover Sep 20 '18 at 11:07
  • I do aware about the different path between debug and release. However this is a ReactNative project which is crossplatform. The path for Native Android is handled by RN and I don't see debug path nor release path. There is only a standard AndroidManifest.xml – Isaac Sep 20 '18 at 11:10
0

Do this

a) Open android studio. Build --> Generate Signed APK and click Next

b) Copy your keystore path and key alias.

enter image description here

c) Now Open terminal and enter:

keytool -list -v -keystore "key store path" -alias "key alias"

d) Enter your key password and this will print out your release SHA1.

e) Then use this SHA1 in google project , Paste it in there and save changes, now run the app again to load map

Update:-

To generate debug key Do this

a) Click on the Gradle tab on the right option bar

b) Go to the root folder -> Tasks -> android -> signingReport

c) Double click, this will build with the signingReport and post in your bottom view your SHA1.

Quick learner
  • 10,632
  • 4
  • 45
  • 55
  • I've mentioned that I do have keystore `myapp.keystore` run the command `keytool -list -v -keystore mypp.keystore` will show me the keystore's SHA-1 – Isaac Sep 20 '18 at 11:30
  • Your answer is suggesting me to re-gen a new keystore but it's hard to convince that the problem is coming from a faulty keystore – Isaac Sep 20 '18 at 11:31
  • you should cross check it dear :) and you should generate the Release and debug key both to cross verify at your end – Quick learner Sep 20 '18 at 11:42