Google App Engine with Android - Endpoint Testing on a Real Device

I followed the tutorial in Creating an Endpoints Outline from an Android Project . Everything compiles and looks promising. Backend up, I changed CloudEndpointUtils # LOCAL_ANDROID_RUN to "true". but when I try to test the application on a real device (not an emulator) im failing on -

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

So, I looked at CloudEndpointUtils and saw that setting LOCAL_ANDROID_RUN to “true” causes the application to look for DevAppServer at http://10.0.2.2:8888 , which is the virtual emulator router. but im doesn't use emulator. so I tried to change the constant by holding this url to http://127.0.0.1:8888/ , but still no luck. im now not working -

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

I thought it could be because my computer is behind a firewall, so I turned it off, but still nothing.

Any suggestion would be appreciated.

+6
source share
7 answers

Add

 --address="0.0.0.0" 

as an address parameter of the server of the application server for receiving all incoming connections.

0
source

If you want to do this in Android Studio, install httpAddress as follows in the build.gradle file

 appengine { ... httpAddress = "0.0.0.0" } 
+12
source

To complete this

  • Enter LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = your IP address (this is in your Android application)
  • Right-click the App-Engine project -> Run-> Run Configurations -> Web Application (left panel) -> your application project.

2. (Contnued) Go to Arugments → add exactly the same

- 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 each time you access the Internet using a key or some kind of dynamic IP service.

Thanks, this works great.

+7
source

There are many answers here, but I found them messy or incomplete. To start a local server on your computer and test it using a real device, follow these steps:

1) Add httpAddress = "0.0.0.0" to the appengine block in the build.gradle file of the backend module (Google Cloud Endpoint), for example:

 appengine { ... httpAddress = "0.0.0.0" } 

According to the commentary on the question, this means that "will take from anywhere."

2) Run your server module locally (i.e. start the web server). This is trivial: select the backend configuration from the drop-down menu and click the green button. You can find more detailed instructions here .

Now you can open a browser (on your computer) and go to http://localhost:8080/ and browse the web page using "Hello, Endpoints!". and much more.

3) Find the IP address of your computer (on a Mac, go to System Preferences → Network), and then set it as the root URL in the code of the Android application, for example:

 MyApi.Builder builder = new MyApi.Builder( AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null ).setRootUrl("http://192.168.1.36:8080/_ah/api/") 

What all!

+5
source

Locally testing the endpoints of a Google deadlock due to the lack of an address localhost -address = "0.0.0.0" may not be enough.

My endpoints threw a 404 Not Found error when accessing from non-localhost. I resolved it by including the path parameter in the API design .

My API annotation looked like this:

 @ApiMethod(name="saveResponse", httpMethod = "post", path="saveResponse) public Response saveResponse(@Named("answerString") String responseString) 
+1
source

Follow point 2. point by user248187 2. (Contnued) Go to Arugments → add exactly the same way --address = 0.0.0.0 --port = .......

Now, on the Android client code, you need to change the request IP address (RootURL) of your services to the local IP address. You can do this using builder.setRootUrl (). It's good that you add an apartment for outomatice on your Android client, then it can quickly switch between local and deployed app-engiene. For instance:

 //........................ private boolean mFlatLocalHostServer=true; private static final String LOCAL_IP = "192.168.1.11"; //Ip debug server public static final String LOCAL_SERVER_IP = "http://"+LOCAL_IP+":8888/_ah/api"; //...................... Mydataendpoint.Builder builder = new Mydataendpoint.Builder( AndroidHttp.newCompatibleTransport(), new GsonFactory(), mCredential); //request the service to local ip if(mFlatLocalHostServer){ builder.setRootUrl(LOCAL_SERVER_IP); } Mydataendpoint service = builder.build(); response=service.insertMyData(mydata).execute(); 
0
source

The address 10.0.2.2 is designed to access the local host using the emulator, to access the local host using a real device, follow these steps

- unscrew your command line (cmd) run ipconfig. - Install ipaddress on your computer and replace 10.0.2.2 with it; - Install and run on your device.

Hope this helps someone

-2
source

Source: https://habr.com/ru/post/950719/


All Articles