2

I'm following this tutorial to try to make an andorid app with a backend on google app-engine. I'm at the point where I want to test the connection between my app and GAE Api locally so I try to execute the following code on my Nexus 5 phone (not emulated).

MainActivity.java

public class MainActivity extends FragmentActivity {

    private final String DEBUG_TAG = "MainActivity";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    /**
     * AsyncTask for calling Mobile Assistant API for checking into a place (e.g., a store)
     */
    private class CheckInTask extends AsyncTask<Void, Void, Void> {
        /**
         * Calls appropriate CloudEndpoint to indicate that user checked into a place.
         *
         * @param params the place where the user is checking in.
         */
        @Override
        protected Void doInBackground(Void... params) {
            CheckIn checkin = new CheckIn();
            // Set the ID of the store where the user is.
            // This would be replaced by the actual ID in the final version of the code.
            checkin.setPlaceId("StoreNo123");
            Checkinendpoint.Builder builder = new Checkinendpoint.Builder(
                    AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                    null);
            builder = CloudEndpointUtils.updateBuilder(builder);
            Checkinendpoint endpoint = builder.build();
            try {
                endpoint.insertCheckIn(checkin).execute();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    }
}

And I get this

And I get this

Where I shouldget this

Where I shouldget this
(source: google.com)

And the log shows : java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 8888) after 20000ms

No CheckIn is available on the "entity kind" list

  • I've lauched the appengine locally i get : INFOS: Dev App Server is now running
  • I've CloudEndPointUtils.java setting to : LOCAL_ANDROID_RUN = true; LOCAL_APP_ENGINE_SERVER_URL = "http://localhost:8888/"; and LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = "http://10.0.2.2:8888";

I feel like it's because I'm using a physical device for debugging...

What do you think and how to make it work ?

(I can't figure out how run an emulator of android on my computer so if there is another solution that would be great)

Edit: I've tried to deploy the app but I'm having the same issue with the same log error.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
dekajoo
  • 2,024
  • 1
  • 25
  • 36
  • I would suggest that first test the api with Google api explorer. using http://10.0.2.2:8888:/_ah/api/explorer . If you are able to access it then there might be an with the server url. builder.setRootUrl("http://10.0.2.2:8888:/_ah/api"); – pankajanand18 Sep 16 '14 at 19:45
  • Did you enable Dev server to listen to requests from local network? http://stackoverflow.com/questions/4022793/gwt-appengine-app-in-dev-mode-not-available-on-local-network/4022803#4022803 – Peter Knego Sep 17 '14 at 06:26

1 Answers1

1

This is beacause 10.0.2.2 is the address of localhost when using the emulator. If you want to try it on your device and all your computer and device are connected to the local network, try changing the server address to http://local-network-ip:port/_ah/api. When launching the appengine application set the host address to 0.0.0.0 to make it accessible to other machines on the network.

loosebazooka
  • 2,363
  • 1
  • 21
  • 32
  • I have put : `protected static final boolean LOCAL_ANDROID_RUN = true;` `protected static final String LOCAL_APP_ENGINE_SERVER_URL = "http://0.0.0.0:8888/";` `LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = "http://192.***.0.3:8888";` But I have the same issue. Am I doing something wrong ? – dekajoo Sep 18 '14 at 11:00
  • 1
    When launching appengine you have to explicity set it to 0.0.0.0, sounds like you're using Eclipse, this question pretty much answers how to do it : http://stackoverflow.com/questions/7534967/is-there-any-way-to-access-gae-dev-app-server-in-the-local-network – loosebazooka Sep 18 '14 at 15:30
  • Ok I feel I'm almost there, now I can access the server through `http://192.***.0.3:8888/_ah/admin/` But I still have the same result there with another log error : `java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8888) after 20000ms: isConnected failed: ECONNREFUSED (Connection refused)` – dekajoo Sep 18 '14 at 16:38
  • Should I put : `String LOCAL_APP_ENGINE_SERVER_URL = "http://192.168.0.3:8888";` `String LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = "http://192.168.0.3:8888";` In the CloudEndpointUtils.java of my android app ? – dekajoo Sep 18 '14 at 17:21
  • Yeah, you could try that, it looks like the connection is still trying to hit localhost (instead of explicitly 192.168.0.3) with whatever configuration your tried last. What I would check is which variable is being passed to the endpoints builder, when testing on your phone that must be set to the 192.168.0.3 address. – loosebazooka Sep 18 '14 at 17:37
  • Ok, I had completly different issue (after the -a 0.0.0.0 that you guys solved) in the config solved here : http://stackoverflow.com/questions/18618621/why-i-am-getting-error-in-android-while-inserting-data-using-endpoints-of-google – dekajoo Sep 18 '14 at 17:46