Importing a go backend endpoint module into an Android Studio project

Hi all,

I am going to configure an existing android studio project to use an cloud endpoint client module. You would usually create a cloud endpoint module using the android studio -> New Module -> Google Cloud Module. But this only works for java language bindings. This post is useful for those who already have a endpoint module in one of python/go/php and want to use the corresponding client libraries in android studio.

Here are the steps

Step 1 : Generate the cloud endpoint module

#<service> is the name of the service you use in endpoints.RegisterService
$ URL=<service>/v1/rest
$ curl -s $URL > rest.discovery.doc

# Check if the discovery doc is generated properly
$ less rest.discovery.doc

#Now run (part of the go development server, in PATH)
$ gen_client_lib java rest.discovery.doc

At the end you will find a .zip file in the same directory as the rest.discovery.doc. Now the generation part is done.

Step 2: Download the required libraries

We need to setup Android Studio with the required libraries an 'Endpoint android client module' might use. To install the libraries,

  1. Start Android Studio.
  2. Close any projects currently open (File > Close Project.)
  3. Click Configure > SDK Manager in the Quickstart pane to display the Android SDK Manager.
  4. Select the following items in the Android SDK Manager, under Tools:
    • Android SDK Tools
    • Android SDK Platform-tools
    • Android SDK Build-tools (19.0.1)
  5. Select the following items under Android 4.4.2 (API 19):
    • SDK Platform
    • Google APIs
  6. Select the following items in the Android SDK Manager, under Extras:
    • Android Support Repository
    • Android Support Library
    • Google Play Services
    • Google Repository
  7. Click Install Packages and wait for the install to finish.
Note: At end you could perhaps see messages which says that a higher version of the app is already present. That is perfectly fine. Also this is a generic list and should cover most of the cases, but you can find it too much if it's a Hello World example and would be too less for a "Microsoft Climatology" app.

Step 3: Setup the endpoint client library

After the packages are installed, now you are ready to import the generated endpoint module to the project. I am going to discuss on using the generated sources, and the dependencies.

  1. Extract the zip file created in Step 1 and find a jar file with the name of your service. Extract that jar file and you will have some sources inside it. Add these source files to your android project (Just copy them inside your src folder)
  2. Now in the extracted zip, find a folder by name "libs". Copy that folder and paste it inside your android project. The destination folder should be parallel to the "src" folder.
  3. Once copied, from android studio -> Project explorer view , you should be able to see the libs folder. Expand it and select all the .jar files under it. Right click and select "Add as Library".
That's it. Now you should be able to successfully build them. To use that in your app follow the second part of the tutorial (i.e Connecting your android app to the backend) in this link