I'm devolping an android app that heavily uses Rest Services.
For developing and debugging, I run the Rest server locally (on my notebook). At home, I have static IP Adresses and therefore, I can put
a static String in my build.gradle.
But if I work from somewhere else, I always have to check my notebook's ip address and edit my build.gradle.
Now I'm curious: Is there a way to insert the current local IP address into my build.gradle automatically?
android {
...
buildTypes {
debug {
...
resValue "string", "host_name", "192.168.0.102" // <--- should be set automatically
}
release {
...
resValue "string", "host_name", "example.com/rest/"
}
}
You can use Groovy methods to find the local IP address:
resValue "string", "host_name", InetAddress.localHost.canonicalHostName
Alternatively you also could use hostAddress instead of canonicalHostName.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With