Refer – Complete implementation for storing API_KEY in gradle properties to avoid uploading to Github.
-
Add
gradle.properties
into.gitignore
file -
Add line in
gradle.properties
fileAPI_KEY="CopyYourAPI_KEYhere"
-
Add below line in
app/build.gradle
within thedefaultConfig
buildConfigField("String", "API_KEY", API_KEY)
-
Use Key using the following statement
String API_KEY = BuildConfig.API_KEY;
Copy this wherever you need API_KEY
It will save your efforts to add and remove API_KEY while committing code in Github.