Importing a go backend endpoint module into an Android Studio project
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=https://my-app-id.appspot.com/_ah/api/discovery/v1/apis/<service>/v1/rest $ curl -s $URL > rest.discovery.doc # Check if the discovery doc is generated properly $ less rest.discovery.doc #Now run endpointscfg.py (part of the go development server, in PATH) $ endpointscfg.py 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,
- Start Android Studio.
- Close any projects currently open (File > Close Project.)
- Click Configure > SDK Manager in the Quickstart pane to display the Android SDK Manager.
- 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)
- Select the following items under Android 4.4.2 (API 19):
- SDK Platform
- Google APIs
- Select the following items in the Android SDK Manager, under Extras:
- Android Support Repository
- Android Support Library
- Google Play Services
- Google Repository
- Click Install Packages and wait for the install to finish.
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.
- 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)
- 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.
- 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".