Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine with Android - testing endpoints on real device

I've been following the tutorial in Creating an Endpoints Backend from an Android Project. Everything is being compiled and looks promising. The backend is up.

I changed CloudEndpointUtils#LOCAL_ANDROID_RUN to true. But when I try to test the app on a real device (not emulator) I'm failing on:

java.net.SocketException: failed to connect to /10.0.2.2 (port 8888) after 20000ms: isConnected failed: EHOSTUNREACH (No route to host)

So I looked at CloudEndpointUtils and saw that setting LOCAL_ANDROID_RUN to true makes the app look for DevAppServer in http://10.0.2.2:8888, which is the emulator virtual router.

But I'm not using the emulator. So I tried to change the constant holding this url to http://127.0.0.1:8888/ but still no luck. I'm now failing on:

java.net.ConnectException: failed to connect to /127.0.0.1 (port 8888) after 20000ms: isConnected failed: ECONNREFUSED (Connection refused)

I thought it might be because my PC is behind a firewall, so I disabled it, but still nothing.

Any suggestion would be appreciated.

like image 531
AsafK Avatar asked Jul 31 '13 13:07

AsafK


2 Answers

If you want to do this in Android Studio, set httpAddress as follows in your build.gradle

appengine {

  ...

  httpAddress = "0.0.0.0"
}
like image 99
kg. Avatar answered Nov 15 '22 06:11

kg.


To accomplish this

  1. Put LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = your IP address (this is in your android App)
  2. Right click on App-Engine project -> Run-> Run Configurations -> Web Application(left bar) -> your app-engine project.

2.(Contniued) Go to Arugments -> add exactly like this

--address=0.0.0.0 --port=.......

*to get your ip address, go to cmd -> ipconfig -> add (IPV4 address with port number) in step 1

important note: Please change this everytime in case you are accessing internet from dongle or some dynamic IP internet service

Thankyou ... this works perfectly

like image 42
user248187 Avatar answered Nov 15 '22 08:11

user248187