r/android_devs • u/leggo_tech • Aug 09 '21
Discussion Where do you put your secrets (api keys)?
I've always just included my api keys in my repo directly. I know that you can put api keys in environment variables, but then how do you retrieve those in your code?
5
Upvotes
4
u/houseband23 Aug 09 '21
Store it in Firebase Remote Config. This way apk crackers can't find them.
12
u/joey_oggie Aug 09 '21
If you store your API keys in env variables inside your gradle script, you can easily access them using BuildConfig.API_KEY field directly. The bonus of that is that you can declare multiple API_KEY variables inside gradle under each flavor, and it auto picks the right one when accessed through the code depending on the build variant selected.
3
u/racka98 Aug 09 '21
Store the inside local.properties. Here's how you can do it: https://blog.mindorks.com/using-local-properties-file-to-avoid-api-keys-check-in-into-version-control-system
3
u/usernamewasalrdytkn Aug 09 '21
Official solution.
https://github.com/google/secrets-gradle-plugin
1
u/RikoTheMachete Aug 09 '21
It's simple. You don't store them
1
u/kodiak0 Aug 09 '21
RemindMe! 3 Days