You can run and test your backend locally, and deploy the backend using Android Studio.
Running and testing the backend locally
After adding the Endpoints backend template, you should test it locally to make sure your environment is functioning properly. To run the backend template locally:
Click Run > Edit Configurations to open the Run/Debug Configurations form:
Note that when you add the backend module template to your project a new run configuration is created for the backend; it has the module name you assigned during backend creation.
In the left pane, under App Engine DevAppServer, locate the backend module you just added, select it, and click OK.
Click Build > Rebuild Project and wait for the build to finish.
Select Run > Run
<your-backend-module-name>to launch the backend in the local App Engine development server in Android Studio:
Wait for the backend to start up in the development server; when it finishes loading, a message similar to the following is displayed in the console:
Jun 18, 2014 4:07:30 PM com.google.appengine.tools.development.AbstractModule startup INFO: The admin console is running at http://localhost:8080/_ah/admin Jun 18, 2014 4:07:30 PM com.google.appengine.tools.development.DevAppServerImpl doStart INFO: Dev App Server is now running
Navigate to http://localhost:8080 on the machine running your Android Studio project. If everything went well, you should see the following page:
(The page shown is for the Endpoints backend. The page for the other backend types will be slightly different.)
Notice the links at the top of the page, especially the link that takes you to the Google Cloud Platform Console, where you can create or configure a project. You'll need a project to deploy your backend after your development and testing work is complete.
At this point, the default backend from the template is successfully running. However, your Android app is not yet connected to the backend. To access the backend, you need to add some code your Android app as described in the appropriate README file:
- App Engine Java Servlet Module
- App Engine Java Endpoints Module
- App Engine Backend with Google Cloud Messaging
You'll also need to add whatever customized behavior you want your backend to have.
Testing the Endpoints backend using API Explorer
For backends that have Endpoints, you can test the functioning of the API directly using the built-in Google API Explorer:
Start and run your backend locally as described previously.
Navigate to http://localhost:8080/_ah/api/explorer on the machine running your Android Studio project. If everything went well, you should see a page similar to the following:
Click the API name, for example myApi API, to display the methods available from this API.
Click a method, for example, myApi.sayHi to display the Explorer form for this method:
Supply a value for the input field if it has one; using the default backend as an example, supply your name in the name field. Click Execute and check the Response for the expected response.
If your backend is working locally, you can deploy it to Google App Engine.
Before deploying your backend, you need to create a Cloud project for it and add the project ID to your backend, as described in the README for your backend template (Servlet Module/ Endpoints Module/ Backend with Google Cloud Messaging) To deploy your backend to App Engine from Android Studio:
Stop the backend, if it is running locally, by selecting Run > Stop.
Run Build > Deploy Module to App Engine.
- If you are running this task for the first time, you will be prompted to sign-in with your Google Account. Choose an account and sign in.
In the Deploy to App Engine dialog, select your module. From the Deploy To: dropdown list, choose a Cloud Platform Console project (in this example,
Scroll to the bottom of the dropdown list if you need to create a new project or sign in with a different account:
- To create a new project, scroll to the bottom of the dropdown and click Click Here. This takes you to the Cloud Platform Console to create the project. Back in the dialog in Android Studio, click the Refresh button to include your new project in the dropdown. Select the new project.
- If you want to create a new account or specify a different existing account, scroll to the bottom of the dropdown and click Add Account.
Back in the Deploy to App Engine dialog, click Deploy. You can monitor the status of your deployment in the Android Studio console.