Home > Software engineering >  How can I store sensitive data in Android studio
How can I store sensitive data in Android studio

Time:09-22

I have some passwords and API keys for my app that I need to use.

For other development environments I've used, we would make a .env file, put all of our sensitive data in there, save that .env file to a password manager, and then let developers know to pull it down to start a project, and have the project read the .env file into the application for use. The .env file is never committed to the repository and is set to have git ignore it.

What's the best way to do this in Android development using Java?

CodePudding user response:

You can create a properties file, put in under your app's folder and add it to .gitignore:

Example of content of a properties file called passwords.properties:

password1=123456
password2=qwerty

In you build.gradle file, import it and use the values from the file:

def passwordsPropertiesFile = rootProject.file("app/passwords.properties")
def passwordsProperties = new Properties()
passwordsProperties.load(new FileInputStream(passwordsPropertiesFile))

And in order to get a value use:

passwordsProperties['password1']
  • Related