Running, Testing, and Deploying the Backend
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 and do the Gradle sync as described, 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 a page similar to the following:
(The page shown is for the Endpoints backend. The page for the other templates will be slightly different.)
Notice the links at the top of the page, especially the link that takes you to to the Google Developer Console, where you can create or configure a Cloud project. (You'll need a cloud 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: you'll need to add some code to your Android app so it can access the backend, as described in the appropriate template 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 backends 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.
Deploying backends
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 .
-
Select Tools > Open Terminal .
-
Enter the command
./gradlew backend:appengineUpdate
-
If you are running this task for the first time, you will be prompted to sign-in with your Google Account. After choosing the account and signing-in, give permissions to Google App Engine's
appcfg
tool and copy-paste the generated key back into the terminal window:Then press Enter to deploy.
Your app is now deployed and ready for clients.