Introduction
Hello guys ππ, welcome back to another article, in our previous article we discussed
how to navigate the obstacles of Navigation Compose.
In this article, we'll learn how to effortlessly manage our API Keys and secrets in our android project using
the secrets Gradle Plugin
Normally when working in our android projects we find ourselves consuming different kinds of APIs which
probably need API Keys to be accessed. Normally we'd want to exclude these API Keys from our version control
for security purpose, so what we do is include the given API Key in our local.properties file generated
by Android Studio which is by default excluded from version control. However, reading from this file in
our project sometimes involves some boilerplate code in our build scripts. Some of the boilerplate would
look something like this
// Read API_KEY for build file
val API_KEY: String = gradleLocalProperties(rootDir).getProperty("API_KEY")
// Include it as a build field in your build variants
...
So to deal with this issue the Google team came up with a plugin called the Secrets Gradle Plugin
that abstracts that build logic for us and does everything for us behind the scenes. The need for this plugin
arose when they noticed developers need to hide their Maps API Keys when working with Google Maps in their
android projects
Using the secrets plugins is simple... Just add the plugin to your project and apply it to your app module then
it will read from your local.properties file. The read variables will be included in your generated BuildConfig class at
compile time. For more information on customization check our their README.md
Thank you for reading and I hope you learnt something new until next time .....Bye.
Top comments (0)