Connecting the Conference Central Android App
to Your App Engine Exercise Backend

Optional exercise for Android developers

This is an optional exercise for students who are familiar with Android development and have a development environment set up. (If you are new to Android development and would like to get started, get your feet wet with the Android Getting Started training or the new Udacity course - Developing Android Apps - Android Fundamentals).

In this exercise, you will take an existing Endpoints-enabled Android application “Udacity - Conference Central” and modify it to connect to your own backend application. The purpose of this exercise is to give you a high-level view of using Endpoints in an Android application without the need for writing an application from scratch.

What you will learn

What you will NOT learn

What you will do

To change your Android app to work with your backend, you need to:

1. Create a signing key for Android

Use the provided debug key

Generate a new key

2. Find the SHA1 of your signing key

3. Client IDs in the Google Developers Console

Web Client ID

Android Client ID

4. Change ANDROID_CLIENT_ID

5. Download the Android app source code

6. Import the Android project into Android Studio

7. Change the WEB_CLIENT_ID

8. Generate the client library in the AppEngine project

9. Add the client library to your Android project

10. Create & sign the APK

11. Install the APK

1. Create a signing key for Android

You can generate your own signing key, or you can use the provided debug key.
See
Signing Your Applications for more information on signing keys.

Use the provided debug key

When you build your Android application in debug mode, the SDK automatically creates a debug key and signs the application with it. See Signing in Debug Mode.

Generate a new key

Follow the instructions in Signing in Release Mode.

In short:

  1. keytool -genkey -v -keystore my-release-key.keystore -alias \ <alias_name> -keyalg RSA -keysize 2048 -validity 10000
  2. Enter a password (make it a good one!)
  3. Follow the prompts to enter the rest of the information.

2. Find the SHA1 of your signing key

See the Installed applications section of the Google Developer Console documentation.

If you are using the debug key:

keytool -exportcert -alias androiddebugkey -keystore $HOME/.android/debug.keystore -list -v

For your personal key, replace the alias and keystore path arguments with your own.

The SHA1 fingerprint will be in the output, looking something like this:

Certificate fingerprints:

MD5:  9F:30:BF:5B:67:92:A7:D1:FE:2B:38:D3:72:B5:83:E4

SHA1: BB:75:F9:CB:23:D9:9A:5A:B4:B8:12:36:F0:8E:86:2A:24:C8:6D:2E

SHA256: 21:5A:FF:48:C9:7B:D5:7B:0C:23:02:B3:03:2E:0A:1D:20:2E:97:38:7E:77:02:91:38:73:E0:E6:1B:AD:B8:B1

Signature algorithm name: SHA1withRSA

Version: 3

3. Client IDs in the Google Developers Console

Web Client ID

You should already have a Web Client ID from developing the backend application, follow these steps to find it:

  1. Open the Google Developers Console.
  2. Go to your Project.
  3. Under APIs & auth, click Credentials.
  4. If you don’t have a Client ID, click the red CREATE NEW CLIENT ID button and create a Web application Client ID.
  5. Note the value in the Client ID field, which is your WEB_CLIENT_ID for your Android app.

Android Client ID

In the Google Developers Console, under APIs & auth –> Credentials

  1. Click the click the red CREATE NEW CLIENT ID button
  2. Click Installed application
  3. Click Android
  4. Enter this package name: com.udacity.devrel.training.conference.android
  5. Insert the SHA-1 key that you obtained earlier.
  6. Leave deep linking disabled.


Dialog for Android Client ID creation:

Screen Shot 2014-05-16 at 19.20.58.png

Entry for Android Client ID after creation:

Screen Shot 2014-05-19 at 15.02.07.png

4. Change ANDROID_CLIENT_ID

  1. In the App Engine project source code find the file: src/main/java/com/google/devrel/training/conference/Constants.java 
  2. Change the ANDROID_CLIENT_ID to the one that you just created.

5. Download the Android app source code

TODO: a link to public GitHub repo & link to zip with the source code.

6. Import the Android project into Android Studio

When Android Studio complains about missing things, allow it to fix them.

If Android Studio still complains:

Open Tools-> Android->Android SDK and install the missing SDKs (e.g. Google Repository, Play Services, and Build Tools 19 under Extras)

7. Change the WEB_CLIENT_ID

  1. In the Android project source code find the file: app/src/main/java/com/udacity/devrel/training/ \
  1. conference/android/AppConstants.java 
  1. Replace the existing WEB_CLIENT_ID with the Client ID for web application.

8. Generate the client library in the AppEngine project

See: Generating a client library for Android using Maven

9. Add the client library to your Android project

  1. Copy the library to the Android project workspace, under app/libs (replace the existing one). Right-click and and choose “add as library”.
  2. Refresh the project. Your library should now be visible.
  3. Change the imports and other usages from ‘com.appspot.udacity_extras.conference’ to your own library in the following files:

Screen Shot 2014-05-19 at 15.28.04.png

10. Create & sign the APK

  1. In Android Studio, choose Build-> Generate Signed APK.
  2. Browse to the keystore you want to use, enter credentials, and create the APK.
  3. The new apk will be in your workspace as app/app.apk
  4. Follow the instructions in Align the final APK package.

11. Install the APK

To run your application on the Android device:

  1. Remove the original Conference Central application from your device, if you have it installed.
  2. Copy your APK to your Android device and run it.

You may need to change your security settings to allow installation of apps not from the Play Store.