I am developing an app for Android that connects to my server. As usual my server during development is on a laptop and its ip is changing. I would like to detect ip address of my development machine i.e.
InetAddress.getLocalHost().getCanonicalHostName()
...and inject it into android strings.xml file so my Android app would connect to right ip during development.
I am struggling with determining where to get info what kind of buildType is run following part can be executed each time:
android {
buildTypes.each { buildType ->
if(buildType.name == 'debug') {
def host = InetAddress.getLocalHost().getCanonicalHostName()
}
}
}
Let's say that that host is determined right now. However I am still not sure how to replace host in strings.xml file in order to connect to the right host. I cannot call processResources as following exception is thrown:
Could not find method processResources() for argument [build_11onjivreh0vsff0acv5skf836$_run_closure3@cbbe2cf] on project
Any suggestion or source code would be appreciated.