To avoid not having your API-KEY in your code, one of the ways is to have API-KEY in gradle.properties of your home directory.
Create gradle.properties file, if you dont find one. This Key resides in your local machine.
gradle.properties (Global Properties)
“buildConfigField” field will configure the variable to be accessable.
With the above changes,
If you need to access api-key in Java use BuildConfig
Example: String api_key = BuildConfig.ApiKey
If you need to access api-key in any Resources use @string/api_key
Example: = "@string/api_key"
Below are the few References which discuss various ways: