You can use a not versioned file called as you want, let's say api.keys with this content:
debugMapsApiKey=xxxxXXXxxxx
releaseMapsApiKey=xxxYYYxxx
Put it in your root project folder.
You read this file in your build.gradle file in a way like that:
def apiKeysFile = rootProject.file("api.keys")
def apiKeysFile = new Properties()
apiKeysFile.load(new FileInputStream(apiKeysFile))
[...]
debug {
buildConfigField "String", MAPS_KEY, apiKeysFile['debugMapsApiKey']
}
release {
buildConfigField "String", MAPS_KEY, apiKeysFile['releaaseMapsApiKey']
}
And you can access it in code through
BuildConfig.MAPS_KEY that if you build in debug you will have "xxxxXXxxxx" value, instead in release you will have "xxxxYYxxxx".
And if you want to access on XML you could use resValue that create a string resource.
debug {
resValue "string", MAPS_KEY, apiKeysFile['debugMapsApiKey']
}
release {
resValue "string", MAPS_KEY, apiKeysFile['releaseMapsApiKey']
}
In this way you could also get it in code with
getString(R.string.MAPS_KEY)