Monday 24 November 2014

Setting up GPE and running an AppEngine Connected Android Project on Emulators and Devices

This is a simple post that provides a quick walk-through to setup Google Plugin for Eclipse (GPE) and then running  the sample App Engine connected android project on the real devices and on emulators.

Actually this post is more about getting the project running on the android device and emulators rather than configuration of Google Plugin for Eclipse because there will not be any changes in the steps to configure it from the official documentation.

Apart from setting up GPE, there is one more important configuration step that is required to carry on with the a project i.e creating project entry in the Google Api console.

So now we will go through in steps to setup GPE to create an App Engine Connected android project.


1. Setting Up GPE :

    Simplest way to setup the plugin is from this link
    https://developers.google.com/eclipse/docs/updating_the_plugin

    Choose the plugin download and install link based upon the version running on your system ie. out of the following supported eclipse versions
        a. Google Plugin for Eclipse 4.3 (Kepler).
        b. Google Plugin for Eclipse 4.2 (Juno).   
        c. Google Plugin for Eclipse 3.7 (Indigo).


2. Create Project on API Console

    Apart from setting up GPE, there is one more important configuration step that is required to carry on with the a project i.e creating project entry in the Google Api console(https://code.google.com/apis/console).

    As project is created you will need to create a server key by navigating to API's and Auth menu under your project. Then choose Credentials sub-menu where you can find an option to create keys. Click on it and choose Server key to proceed which will then create a server key. 

Current sample requirement : You will need to enable Google Cloud Messaging for Android service from the API's section as it is a part of our sample app.
      
    Keep an account of both the project number and this created server key which will be used when you will begin with creation of project in eclipse.


3. Create New Project in Eclipse
    Create a new app engine connected android project in eclipse by choosing
    File -> New Project -> Android -> App Engine Connected Android Project .
    https://developers.google.com/eclipse/docs/endpoints-androidconnected-gae

    Note :
    Since here the project created from the New Project wizard is an android project which has an app engine backend.

    The sample Android app registers with the backend via an Endpoints API and receives messages from the backend via Google Cloud Messaging for Android. The sample app consists of required boilerplate code along with sample code that can be easily replaced by your own app code.

    The App Engine backend provides an API to register Android clients and a Web UI to broadcast messages to clients.

 Above wizard creates two projects in the workspace, one is android client and other a web application (Backend app) which provides an api for the clients.

Please note that we will not be covering how Cloud EndPoints api is used to register with the backends.

Now you can see that there are two projects in the workspace. Clean and build the complete workspace or you can simply do for the two projects.

The major tasks that we will be covering in this project are :
1. Running app engine server project on local machine. You can also deploy this application on cloud and  then make use of it. In our case we will be running it on our local machine.

2. Running android client both on android devices and emulators.

Once done with the build process successfully, you are good to go with the launch of the android app and app engine based project.

Here we go with the required changes in the two projects to get them running on the real android device and emulators.

Case 1: Using emulators to run android client.
        Web Project :
         Clean and build the web project and run it as web application.

        Android Project :
        In CloudEndpointUtils.java file update the value of constants :
                    -> LOCAL_ANDROID_RUN = true;
      
Clean and build the android project and run it as web application.



Case 2: Using android devices to run android client
          Web Project :
         a. Update the arguments value under Run as -> Run Configurations -> WebApplication ->   Select the Project -> Select Arguments -> Add this ahead --address=0.0.0.0 ahead of  --port=8.8.8.8
                and final value will something like
                --address=0.0.0.0 --port=8888 F:\WorkSpaceDroid\PlayCloudEPoints-AppEngine\war
          b.
Clean, build and run the project again

         Android Project :      
       
In CloudEndpointUtils.java file update the value of constants :
                    -> LOCAL_ANDROID_RUN = true;
                    -> LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID ="your_machine_ipv4_address:8888";



Please add comments if you face any issues.

No comments:

Post a Comment