Troubleshooting App Engine-connected Android projects with c2dm
Posted by David Chandler on May 18, 2012
- 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 firstname.lastname@example.org.
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.