Last active
October 9, 2015 00:43
-
-
Save erd/69ebad5828625a91c5dd to your computer and use it in GitHub Desktop.
Android set localhost address to local ip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
buildTypes { | |
debug { | |
debuggable true | |
buildConfigField "String", "API_HOST", '"http://' + getIpAddress() + ':3000"' | |
buildConfigField "String", "API_PATH", '"/api/v1"' | |
} | |
} | |
} | |
def getIpAddress() { | |
for (NetworkInterface iface : NetworkInterface.getNetworkInterfaces()) { | |
for (InterfaceAddress address : iface.getInterfaceAddresses()) { | |
final String ip = address.getAddress().getHostAddress() | |
if (ip.length() < 15) return ip | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment