I'm having trouble with reaching my Google Cloud Endpoints backend from my Android application. I use the following related tools and libraries:
com.google.appengine:gradle-appengine-plugin:1.9.49
com.google.appengine:appengine-java-sdk:1.9.49
com.google.appengine:appengine-endpoints:1.9.49
com.google.appengine:appengine-endpoints-deps:1.9.49
I've followed the documentation on testing with a physical device against the local development server, which means I've added the line httpAddress = "0.0.0.0"
to the build.gradle
in the backend module, and I connect to the backend using the following code:
SomeApi.Builder builder = new SomeApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);
builder.setApplicationName("someapplicationname");
builder.setRootUrl("http://192.168.1.1:8080/_ah/api/");
builder.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer()
{
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException
{
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
SomeApi api = builder.build();
I then call a method of the created api
using the following line:
api.someMethod("Some random string").execute();
And this is where the problem occurs. This method call triggers the following exception pointing to the same method call (the line above):
W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
W/System.err: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:381)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:373)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:304)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:761)
The strange thing is that the requests doesn't even reach the endpoint. The exception seems to be thrown by the Endpoints library on the client side, because the the server log does not show any signs of error, it contains the log messages printed when starting the server, and that's it.
I have no idea what is causing this, so any help is greatly appreciated!
Turns out that I copied the wrong IP-address from the ipconfig
-output, even though I mentioned I'm using the correct IP-address. Hrrm, embarassing...
After trying (what felt like) every possible solution, I once again checked the IP, and it turned out I'd copied the one labeled Default Gateway
, which was obviously not as correct as the one labeled IPv4 Address
!
So, if you're experiencing the same problem but still you feel like you've done everything correctly, make sure to double check the IP before giving up!