Troubleshooting App Engine-connected Android projects with c2dm
Posted by David Chandler on May 18, 2012
Google Plugin for Eclipse has a wizard to create an Android project with App Engine back end including client push (c2dm). The official tutorial is quite good, but after spending the better part of a day trying to get the Cloud Tasks sample up and running again, I thought it might be useful to post a few tips.
General Tips
- Sign up for c2dm first. Remember the package name and use it when running the Eclipse wizard! The package name is required, and once you choose the package name on c2dm sign-up, it is nowhere visible later. Be patient–it may take an hour or even a day to activate your account.
- Sign in to Eclipse with the c2dm account name you’ll use (see lower left corner–if not visible, you need Google Plugin for Eclipse). It’s easy to forget this, but Debug As | Local App Engine Connected Project requires you to be signed in.
Run on a Phone With the GAE Dev Server
In this scenario, the phone and dev server must be on the same network! Easiest way is to connect to the same wi-fi router. USB cable does nothing. Be aware that most public wi-fi routers don’t allow devices to contact each other, so it will probably work best at home or on your company’s guest wi-fi network.
- Ensure that phone and dev server are on the same wi-fi network. Disconnect both from any VPNs.
- Add -bindAddress 0.0.0.0 to your Web project’s Run Configuration | Program Arguments. This will start the server listening on all addresses, not just the default localhost (which the phone can’t see).
- When you choose Debug As | Local App Engine Connected Android Application, GPE hardcodes your machine’s IP address in assets/debugging_prefs.properties. This is where the Android app looks up the address of the server.
- You can launch/debug the Android app and the Web app independently; however, if your server IP address changes, you must again Debug As | Local App Engine Connected Android Application in order to update the IP address in assets/debugging_prefs.properties.
- In case you wondered, the Android and Web projects are associated in a file in the Android project. You can find it in .settings/com.google.gdt.eclipse.mobile.android.prefs. To associate a different App Engine project with an Android project, simply edit this file and refresh the project.
- If you’re using the GWT dev mode browser plugin, you can still connect to 127.0.0.1. If you connect to the address shown in Development Mode tab (your machine’s network IP address), you may need to allow the address in the dev mode browser plugin. Click the GWT icon in the address bar to do this.
- Make sure you log in to the Web app as the c2dm user, not the default test@example.com.
Run on a Phone Against the Production App
In the production scenario, you’re using real c2dm so the phone doesn’t have to be on wi-fi at all.
- Edit Setup.java and change APP_NAME and SENDER_ID to match your GAE app id and c2dm account.
- Change app id in appengine-web.xml to match your GAE app.
- Deploy to App Engine with your c2dm account.
- Force sign in to GAE app by going to [prod_url]/tasks/. This triggers the security constraint in web.xml to get logged in to GAE. After logging in, you’ll get an error page, but that’s OK. Then go to [prod_url]/ and Say Hello to App Engine. If logged in, you should see a success message.
- If you’ve previously connected an account on a phone to this production app, go to GAE datastore viewer and delete all records.
- In Eclipse, Debug as | Remote App Engine Connected Android project
- On the phone, you’ll be prompted to connect an account. Use your c2dm account. If you have previously connected a different account, go to Menu | Accounts | Disconnect in the app and reconnect.
The CloudTasks project still has a few issues. Feel free to log them in the tracker.
Tim said
More of a question than a comment. Now that the ‘App Engine connected Android application’ wizard is no more, and I’ve broken my link between my Android App and the App Engine (in my Eclipse environment) – I get the message ‘Could no launch debug, the App Engine project was not found’, how do I re-establish the connection?
Tim
David Chandler said
Hi Tim, there’s been some recent discussion on this on the google-plugin-eclipse group. I haven’t paid too close attention, but I think the GPE team is working on an update that re-establishes the connection.
android tutorial beginners said
nice post….
thanks for giving this blog….
i have learn GAE dev server from this post…
i hope keep this blog in future…
SaranSays said
very useful information about google plugin for eclipse has a wizard to create an android application.. currently i am doing android projects.. and also very useful post to know about the GAE Dev Server.. thanks again for the post..
C Tutorial For Beginners said
Good to see the post like this.. i am android developer.. i come to know brief about the GAE Dev Server.. it will be helpful for me in future.. thanks a lot..
Saumya said
Question: on selecting app engine connected android project I’m getting the following error
The selected wizard could not be started.
Plug-in “com.google.gdt.eclipse.mobile.android” was unable to instantiate class “com.google.gdt.eclipse.mobile.android.wizards.NewAndroidCloudProjectWizard”.
com/android/io/StreamException
David Chandler said
Hi Saumya, best place to ask this is on stackoverflow.com with tag google-plugin-eclipse. The GPE team removed the App Engine connected wizard in a recent version but I understand they’re planning to bring it back…