Arunabh Das
Arunabh Das

Reputation: 14342

Generate Cloud Endpoint Client Library in Android Studio using Entity Class Design Pattern

While following the steps outlined here :

https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial/

for creating a cloud endpoint, but using Android Studio instead of Eclipse, I am stuck at Step 9 of the Entity Class Design Pattern as described here :

https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial/#ecdp

In Eclipse, there is a right-click-menu-option for "Generate Cloud Endpoint Client library" when you right-click on the app engine project. However, there is no equivalent option in Android Studio (v1.0.0)

Is this an omission on Google's part or am I missing something.

What is the best workaround for generating the cloud endpoint client library from within Android Studio.

Is there a way to do it from the command-line?

I did find the steps for gradle here :

https://cloud.google.com/appengine/docs/java/endpoints/endpoints_tool

and here :

https://cloud.google.com/appengine/docs/java/endpoints/consume_android

but these are much more time-consuming than the single-step process described in the original link for eclipse.

Upvotes: 1

Views: 1855

Answers (3)

Patrick Flynn
Patrick Flynn

Reputation: 440

We're working on updating that shopping kart sample to use Android Studio.

In the meantime the documentation for generating endpoints in AS can be found here https://cloud.google.com/tools/android-studio/

There is no 'Generate Cloud Endpoint Client Library' task anymore since it's not needed in the Android Studio workflow. Simply building the project will ensure that the client libraries are available to your android app.

Check out the docs for the appengine gradle plugin https://github.com/GoogleCloudPlatform/gradle-appengine-plugin if you want to be able to manually perform some of the endpoint client library steps from the command line using Gradle.

Upvotes: 2

Renaud Tarnec
Renaud Tarnec

Reputation: 83048

As Lucien Murray-Pitts explained, the Builder is not in the Endpoint class but in a auto-generated XXXXApi class.

Imagine your java bean is a class called Portfolio under package com.example.backend

You have to add the following import in the AsyncTask class:

import com.example.backend.portfolioApi.PortfolioApi;

and then you can do

PortfolioApi.Builder builder = new PortfolioApi.Builder(....

Upvotes: 1

Lucien Murray-Pitts
Lucien Murray-Pitts

Reputation: 301

As stated above the libraries are auto-compiled for you, the other point to note that had me confused is where to get the Builder from.

Now as of Android Studio 1.0.1 the original Eclipse instructions are a little out of date for this as well, the "Builder" is no longer buried into the Endpoint class you make. Instead it is rolled into a separate API class to describe the Builder and associated code.

See: https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints

Endpoint Usage from Android would now look like this:

/* OLD
MyEndpoint.Builder builder = ... */

MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), 
                new AndroidJsonFactory(), null)
            // options for running against local devappserver
            // - 10.0.2.2 is localhost's IP address in Android emulator
            // - turn off compression when running against local devappserver
            .setRootUrl("http://10.0.2.2:8080/_ah/api/")
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });

Upvotes: 3

Related Questions