Saving the API Key in gradle.properties

Refer – Complete implementation for storing API_KEY in gradle properties to avoid uploading to Github.

GitHub: Hiding (secret) API keys – Tutorial


  1. Add gradle.properties into .gitignore file

  2. Add line in gradle.properties file API_KEY="CopyYourAPI_KEYhere"

  3. Add below line in app/build.gradle within the defaultConfig

    buildConfigField("String", "API_KEY", API_KEY)

  4. 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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)