git - Is this the right approach to hide my API key in my android project when using gitignore? -


i trying learn basics of git , github along android programming can show work employers in future.

i have done projects requires api keys.i've understood have remove api key before sharing code publicly in github. i've learnt .gitignore can used in git command line ignore files not want upload.

i read lot of stack overflow posts , other q&a sites see have store api key can ignore file using .gitignore. there many suggestions , following 1 of suggestions here store api key in gradle.properties

my_private_api_key=12345 

and in build.gradle like

buildtypes {                 debug{                buildconfigfield("string", "forecast_verification_api_key", "\"" + my_private_api_key +"\"")               minifyenabled false               applicationidsuffix ".debug"               }           }  

and in code reference like

string api_key = buildconfig.forecast_verification_api_key; 

now want make sure if aproach correct before uploading project publicly.

my .gitignore file this

.gitignore

i see .gitignore has .gradle in it. mean gradle.properties have stored api key ignored?i totally confused.am following right approach?

i'm not familiar specific software package you're using, can use git status see being tracked. if gradle.properties file disappears untracked files section have done right.

i don't think .gradle work in .gitignore if file calledgradle.properties. people use *.example if want ignore 1 whole class of file extension. name full file in .gitignore, gradle.properties , should disappear git tracking.


Comments