Android DevOps: From a Single Push Command to Production

Image for post
Image for post

Introduction

DevOps refers to a set of well-known practices for automating software deliveries. By design, DevOps allows for easier maintenance and updating through continuous testing, code quality improvement, and feature development. One of the primary objectives of utilizing DevOps is to facilitate developers to perform quick, reliable, and automated publishing without any human interference — a feature known as continuous delivery. This document explains how you can implement DevOps with Android apps.

Continuous Integration

Robust continuous integration is essential for implementing continuous delivery. Although continuous integration is readily available within the Android environment, let us review it again.

  • Proactive Debugging: App building after each push ensures that you can detect potential errors early.
  • Testing Continuity: This feature enables continuous testing.
  • Continuous Packaging: This feature allows you to eliminate human errors during binary code packaging.
  • Accelerated Publishing: Simplifies publishing as you have confidence in every build step.
  • Improved Confidence: You can trust your code and reduce unexpected errors.

Typical Continuous Integration Process

Before implementing continuous integration, you need to prepare an integration server such as Jenkins or Travis. The steps involved in the continuous integration process is as follows.

  1. After the initial job is successful, the next job starts. This job runs integration tests (through Espresso or Robotium) and ensures the user experience quality by reproducing scenarios and checking image content. To do this, you can utilize a connection device (this could be tough if you have difficulties obtaining a CI server), Genymotion, or the latest built-in simulator supplied with Android Studio 2.0 (recommended) for operation.
  2. A separate job will run a code measurement (such as through Sonarqube) to monitor code quality. For example, you can run this job every day at midnight.
  3. Finally, run another job after pushing the master branch or publishing the branch. This job will compile the code and then generate and publish the APK.

Testing is the Key

Testing is very important since it is the only way to prove that the apps run as expected. There are plenty of tools that can help you write a great test code, but you still have to make an informed choice.

Continuous Delivery: Unlimited Upgrading

Trainline EU releases a new version of its booking app, Captain Train, every six weeks. Currently, it is in beta phase, with support for four locales, four language environments, and three types of devices (phones, 7- and 9-inch tablets). The developers create release notes, use the rollout feature, and upload 72 screenshots (6 screenshots 4 locales 3 types). It has an Android Wear companion, currently in test phase.

Developing Your Publisher

This process involves two steps: configuring the console to enable the client and then discovering the APIs. Configuration is the hardest part when you try to establish a connection with Google.

Configuration

First, you have to create a project in the Google console, that is, if no projects are available. Next, enable Google Play Android Developer API.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Discovering APIs

You need to configure the access interfaces through the Java client. To do this, create a Java project in the publisher and add the following dependencies (available in maven central):

http = GoogleNetHttpTransport.newTrustedTransport();
json = JacksonFactory.getDefaultInstance();
Set<String> scopes =
Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER);
GoogleCredential credential = new GoogleCredential.Builder().
setTransport(http).
setJsonFactory(json).
setServiceAccountPrivateKeyId(KEY_ID).
setServiceAccountId(SERVICE_ACCOUNT_EMAIL).
setServiceAccountScopes(scopes).
setServiceAccountPrivateKeyFromPemFile(secretFile).
build();
publisher = new AndroidPublisher.Builder(http, json, credential).
setApplicationName(PACKAGE).
build();
AndroidPublisher.Edits edits = publisher.edits();AppEdit edit = edits.insert(PACKAGE, null).execute();
String id = edit.getId();
Listings listings = edits.listings();Listing listing = new Listing().
setFullDescription(description).
setShortDescription(shortDescription).
setTitle(title);
listings.update(PACKAGE, id, "en_US", listing).execute();
Images images = edits.images();
FileContent content = new FileContent(PNG_MIME_TYPE, file);
images.upload(PACKAGE, id, "en_US", "phone5", content).execute();
// APK upload
Apks apks = edits.apks();
FileContent apkContent = new FileContent(APK_MIME_TYPE, apkFile);
Apk apk = apks.upload(PACKAGE, id, apkContent).execute();
int version = apk.getVersionCode();
// Assign APK to Track
Tracks tracks = edits.tracks();
List<Integer> versions = Collections.singletonList(version)
Track track = new Track().setVersionCodes(versions);
tracks.update(PACKAGE, id, "production", track).execute();
// Update APK listing
Apklistings apklistings = edits.apklistings();
ApkListing whatsnew = new ApkListing().setRecentChanges(changes);
apklistings.update(PACKAGE, id, version, "en_US", whatsnew).execute();

Conclusion

Currently, Android apps support DevOps activities and provide robust continuous delivery capabilities. In the Captain Train example, developers can develop publishing tools to take full control of each step and the content of each key step. Once a release task is complete, they can run it as a script. Similarly, you can also use the Jenkins plug-in or the Gradle plug-in for the same purpose. However, in this method, you must exercise caution and remember to monitor the operation status in the background as you are processing production.

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store