Skip to content

Instantly share code, notes, and snippets.

@erd
Last active October 9, 2015 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erd/69ebad5828625a91c5dd to your computer and use it in GitHub Desktop.
Save erd/69ebad5828625a91c5dd to your computer and use it in GitHub Desktop.
Android set localhost address to local ip
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