Titanium Mobile: java.net.UnknownHostException error when using the AVD emulator

Doing some local development with Titanium and I noticed that when using the xhr object to hit my localhost server (idxdot.dev), and testing using the emulator, I got this error:

(TiHttpClient-1) [7,236164] HTTP Error (java.net.UnknownHostException): idxdot.dev
E/TiHttpClient( 417): java.net.UnknownHostException: idxdot.dev
E/TiHttpClient( 417): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
E/TiHttpClient( 417): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
E/TiHttpClient( 417): at java.net.InetAddress.getAllByName(InetAddress.java:242)
E/TiHttpClient( 417): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
E/TiHttpClient( 417): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
E/TiHttpClient( 417): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
E/TiHttpClient( 417): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
E/TiHttpClient( 417): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
E/TiHttpClient( 417): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
E/TiHttpClient( 417): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
E/TiHttpClient( 417): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1017)
E/TiHttpClient( 417): at java.lang.Thread.run(Thread.java:1096)
I/TiHttpClient( 417): (TiHttpClient-1) [24,236188] Sending error idxdot.dev

I have idxdot.dev set up as a virtual host on my machine, and I can hit it fine doing my local development but not just from within the AVD and it hinted to me that it must be that the network setup in the AVD is not able to access my hosts file and apparently it’s because the address is used internally by Linux. A workaround is to use 10.0.2.2 if you are using Linux or your local WAN/LAN address if you are on Windows (192.168.1.x).

Published by Abou Kone

I am a front end architect with 10+ years of experience in web development. The best part of the process for me is converting ideas into code and solving the technical problems that come along. Alongside providing technical leadership and architectural support to projects spanning multiple industries, I am also experienced in leading discussions with designers, developers, and business stakeholders helping to guide teams in turning complex business workflows or data into easy-to-use web and mobile interfaces. I believe in delivering high quality products and am constantly looking into improving the process and tools use to achieve this goal.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: