0

I am using the Google maps API and therefore need to store a secret (the API key) so the map works correctly.

  1. Where should secrets be stored in a MAUI app?
  2. How to is the secret referenced in the AndroidManifest?

I currently have the API key in string resources and have used it in the AndroidManifest by doing this:

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

I could add the string resources file to the .gitignore but there might be strings in there that aren't sensitive and I might want to commit them.

So where should secrets go and how should they be injected into the AndroidManifest.

Thanks.

  • You are using Maps SDK for Android right? – Yrll Jun 06 '23 at 23:54
  • Yes that's correct – Steve Rosam Jun 07 '23 at 11:00
  • There's a guide for that in the [official documentation](https://developers.google.com/maps/documentation/android-sdk/secrets-gradle-plugin) about secrets gradle plugin where you can store your API key in `local.properties`. – Yrll Jun 07 '23 at 23:48
  • Thanks I'll have a look. I'm not sure it'll work for me since I'm using .net MAUI and not the native Android tools. But maybe it will help. – Steve Rosam Jun 12 '23 at 10:18

1 Answers1

0

Once you've obtained an API key it must be added within the element of your Platforms/Android/AndroidManifest.xml file, by specifying it as the value of the com.google.android.geo.API_KEY metadata:

You could just try the following:

<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="PASTE-YOUR-API-KEY-HERE" />
</application>

Hope it works.

Liqun Shen-MSFT
  • 3,490
  • 2
  • 3
  • 11
  • Hi thanks but that's what I did initially.. then thought hey I shouldn't be checking this file into GitHub. So we need some way of populating that value from environment variables or something. Maybe a build time text replace? – Steve Rosam Jun 12 '23 at 10:16
  • Do you mean this [Use variables in manifest](https://stackoverflow.com/questions/58065984/use-variables-in-manifest). There's not an easy way to use Gradle in Maui. You could raise an issue on Github. – Liqun Shen-MSFT Jun 15 '23 at 01:21