Refer – Complete implementation for storing API_KEY in gradle properties to avoid uploading to Github.
-
Add
gradle.propertiesinto.gitignorefile -
Add line in
gradle.propertiesfileAPI_KEY="CopyYourAPI_KEYhere" -
Add below line in
app/build.gradlewithin thedefaultConfigbuildConfigField("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.