3

I'm new to Android programming and I'm trying to perform an app that sends an image to a server which gives back a result. For that reason, I'm following the google tutorial 2 on App Engine Connected Android. The problem comes when running the phone side of the application, since the emulator does not start and, if I try it with a real device, it says that 'Registration with endpoints failed', a screenshot image of the result is in the link 1.

I've set the LOCAL_ANDROID_RUN to true and I've also inserted the corresponding project number and api_keys. I don't know what is wrong, the console and logcat output are the following:

RUN -AppEngine Console:

feb. 27, 2013 11:36:51 AM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory '/Users/JL/Documents/workspace/p27_2-AppEngine/war' is not an EAR directory. File /Users/JL/Documents/workspace/p27_2-AppEngine/war/appengine-application.xmlappengine-application.xml not detected.
feb. 27, 2013 11:36:51 AM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory '/Users/JL/Documents/workspace/p27_2-AppEngine/war' is not an EAR directory. File /Users/JL/Documents/workspace/p27_2-AppEngine/war/appengine-application.xmlappengine-application.xml not detected.
feb. 27, 2013 11:36:51 AM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory '/Users/JL/Documents/workspace/p27_2-AppEngine/war' is not an EAR directory. File /Users/JL/Documents/workspace/p27_2-AppEngine/war/appengine-application.xmlappengine-application.xml not detected.
feb. 27, 2013 11:36:51 AM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory '/Users/JL/Documents/workspace/p27_2-AppEngine/war' is not an EAR directory. File /Users/JL/Documents/workspace/p27_2-AppEngine/war/appengine-application.xmlappengine-application.xml not detected.
feb. 27, 2013 11:36:51 AM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed /Users/JL/Documents/workspace/p27_2-AppEngine/war/WEB-INF/appengine-web.xml
feb. 27, 2013 11:36:51 AM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed /Users/JL/Documents/workspace/p27_2-AppEngine/war/WEB-INF/web.xml
feb. 27, 2013 11:36:51 AM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties
INFO: Overwriting system property key 'java.util.logging.config.file', value '/Applications/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.7.5/appengine-java-sdk-1.7.5/config/sdk/logging.properties' with value 'WEB-INF/logging.properties' from '/Users/JL/Documents/workspace/p27_2-AppEngine/war/WEB-INF/appengine-web.xml'
java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:344)
    at sun.nio.ch.Net.bind(Net.java:336)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:216)
    at com.google.appengine.tools.development.JettyContainerService.connectContainer(JettyContainerService.java:189)
    at com.google.appengine.tools.development.AbstractContainerService.createConnection(AbstractContainerService.java:243)
    at com.google.appengine.tools.development.AbstractServer.createConnection(AbstractServer.java:71)
    at com.google.appengine.tools.development.DevAppServerImpl$Servers.createConnections(DevAppServerImpl.java:445)
    at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:181)
    at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:333)
    at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
    at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:269)
    at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:245)

RUN phone-side, on real device Console:

[2013-02-27 11:31:53 - p27_2] ------------------------------
[2013-02-27 11:31:53 - p27_2] Android Launch!
[2013-02-27 11:31:53 - p27_2] adb is running normally.
[2013-02-27 11:31:53 - p27_2] Performing com.p27_2.MainActivity activity launch
[2013-02-27 11:31:56 - p27_2] Application already deployed. No need to reinstall.
[2013-02-27 11:31:56 - p27_2] Starting activity com.p27_2.MainActivity on device 31315808870300EC
[2013-02-27 11:31:56 - p27_2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.p27_2/.MainActivity }
[2013-02-27 11:31:56 - p27_2] ActivityManager: Warning: Activity not started, its current task has been brought to the front
[2013-02-27 11:35:21 - p27_2] ------------------------------
[2013-02-27 11:35:21 - p27_2] Android Launch!
[2013-02-27 11:35:21 - p27_2] adb is running normally.
[2013-02-27 11:35:21 - p27_2] Performing com.p27_2.MainActivity activity launch
[2013-02-27 11:35:24 - p27_2] Application already deployed. No need to reinstall.
[2013-02-27 11:35:24 - p27_2] Starting activity com.p27_2.MainActivity on device 31315808870300EC
[2013-02-27 11:35:24 - p27_2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.p27_2/.MainActivity }
[2013-02-27 11:35:24 - p27_2] ActivityManager: Warning: Activity not started, its current task has been brought to the front
[2013-02-27 11:37:06 - p27_2] ------------------------------
[2013-02-27 11:37:06 - p27_2] Android Launch!
[2013-02-27 11:37:06 - p27_2] adb is running normally.
[2013-02-27 11:37:06 - p27_2] Performing com.p27_2.MainActivity activity launch
[2013-02-27 11:37:09 - p27_2] Application already deployed. No need to reinstall.
[2013-02-27 11:37:09 - p27_2] Starting activity com.p27_2.MainActivity on device 31315808870300EC
[2013-02-27 11:37:10 - p27_2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.p27_2/.MainActivity }
[2013-02-27 11:37:10 - p27_2] ActivityManager: Warning: Activity not started, its current task has been brought to the front

LogCat:

02-27 11:36:58.968: D/GCMRegistrar(1684): resetting backoff for com.p27_2
02-27 11:36:58.968: V/GCMRegistrar(1684): Registering app com.p27_2 of senders 658829472559
02-27 11:36:59.296: V/GCMBroadcastReceiver(1684): onReceive: com.google.android.c2dm.intent.REGISTRATION
02-27 11:36:59.296: V/GCMBroadcastReceiver(1684): GCM IntentService class: com.p27_2.GCMIntentService
02-27 11:36:59.296: V/GCMBaseIntentService(1684): Acquiring wakelock
02-27 11:36:59.316: W/AbstractGoogleClient(1684): Application name is not set. Call Builder#setApplicationName.
02-27 11:36:59.328: D/GCMBaseIntentService(1684): handleRegistration: registrationId = APA91bEN9AXnKP8jsVmt3fNj1ziAegl04m4laECFqkzFxbuk2dfdvK3ePCVH_3JOjKehC0EpPgkkIp8t-OJtxTe_E12lw9atzEcHVpsyr_Qdi4UYxQgsW2w3uZQRnbj8Aho_IUjAWKub, error = null, unregistered = null
02-27 11:36:59.328: D/GCMRegistrar(1684): resetting backoff for com.p27_2
02-27 11:36:59.335: V/GCMRegistrar(1684): Saving regId on app version 1
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684): Exception received when attempting to register with server at http://10.0.2.2:8888/_ah/api/
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684): java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 8888) after 20000ms
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.io.IoBridge.connectErrno(IoBridge.java:159)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.io.IoBridge.connect(IoBridge.java:112)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at java.net.Socket.connect(Socket.java:842)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:80)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1009)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:407)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:340)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:458)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.p27_2.GCMIntentService.onRegistered(GCMIntentService.java:169)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:251)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:153)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at android.os.Looper.loop(Looper.java:137)
02-27 11:37:39.511: E/com.p27_2.GCMIntentService(1684):     at android.os.HandlerThread.run(HandlerThread.java:60)
02-27 11:37:39.523: V/GCMBaseIntentService(1684): Releasing wakelock
02-27 11:37:39.562: D/dalvikvm(1684): GC_CONCURRENT freed 134K, 7% free 8586K/9159K, paused 18ms+7ms, total 70ms

Thank you very much.

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
jl.da
  • 627
  • 1
  • 11
  • 30
  • it seems your server is not running....try after restarting the server – Ajit Feb 27 '13 at 11:53
  • Hi @Ajit, thank you very much for answering. I have restarted eclipse and run the server code several times, but the result is the same. Now I've found this [post] [1], but the links that the answer provide don't work for me (changing, of course, 'YOUR-APP-ID' for the Project Number from the Google API console). [1]: http://stackoverflow.com/questions/15047744/gae-cloud-endpoints-api-not-updating-after-deploy – jl.da Feb 27 '13 at 16:39

3 Answers3

3
  1. Make sure the constant LOCAL_ANDROID_RUN is set false in CloudEndPointUtils class which means that our server is not set locally.
  2. Deploy your -AppEngine project to google appEngine by right clicking on the project->google->deploy to app engine.
  3. Adding the url displayed after deploying to CloudEndPints.java to variable as LOCAL_APP_ENGINE_SERVER_URL
Raghav Sharma
  • 780
  • 10
  • 18
0

Your error, java.net.BindException: Address already in use, indicates that the local AppEngine instance is not starting up properly. Normally I see this error when I try to start the local GAE instance when another GAE instance has already bound itself to the port (that is, I start it twice), but in that case your Android app should communicate with the first instance and still function.

Your problem is different -- for some reason, your initial GAE instance cannot bind itself to the port (we know this because the Android app cannot find any local GAE instance). I would try the following, in order, until it works:

  1. Make sure your GAE run configuration is set to bind to port 8888 (if the port is set at 1024 or below, the OS may reject the attempt to bind).
  2. Assuming you use Eclipse, alter your GAE run configuration to "Automatically select an unused port" and see if it starts up okay. If it does, then make this port the one to use in your GAE run config and in your Android app. If this fixes it and you're curious, you may want to see what is bound to port 8888 already.
  3. Find a port (above 1024) which is definitely not bound to anything and try that in your GAE run configuration.
  4. If you get to this point, you won't be able to bind to any ports, which is weird. Write back if it comes to this =)
einnocent
  • 3,567
  • 4
  • 32
  • 42
0

I had the same problem: with the eclipse android app engine connected project, the registration with cloud endpoints server succeeded on emulator with localhost backend, and failed when running on a device with app engine deployed backend. After 3 hours of clearing the cache on my device and searching for answers, I did the following which worked for me, and now the registration with cloud endpoints succeeds on the device and I am able to send GCMs to my device.

  1. right click on client side project > android tools > add support library
  2. right click on server side project > google > generate cloud endpoint client library
  3. delete the app from your phone and clear your phones cache ( for galaxy nexus jelly bean: settings > storage > tap cached data)
  4. make sure the server is not running on your localhost currently
  5. reinstall the app from your computer since you have just updated the support libraries

Hope that helps!!

caitcoo0odes
  • 484
  • 1
  • 6
  • 17