(If I understand) I would use an external executable that prepare a batch file for each build.
The .bat file calls gradle passing a variable (conaining the key) to it:
gradle assemble -Pkey=%key%
Now, inside the gradle script you can get the value of the variable:
def varKey = "$key"
and you can use it to sign the apk:
signingConfigs {
release {
storeFile = file('../key.keystroke')
storePassword = varKey
keyAlias = "My key"
keyPassword = varKey
}
}
EDIT:
Ok, the previous text is useful to sign the apk file with different keys.
To edit the server url using gradle, first you need to store the url and api key into a resource string and use from inside the java class instead of the hard coded strings:
<resources>
<string name="server_url">you.server.com</string>
<string name="api_key">your_api_key</string>
</resources>
now consider the .bat that calls gradle:
gradle assemble -Papi_key=%api_key% -Pserver_url=%server_url%
inside gradle, you get the variable content:
def varApiKey = "$api_key"
def varServerUrl = "$server_url"
Now you need to replace the strings in your resources. I never done it but (for example) you can look at:
How to replace strings resources with Android Gradle