Publishing private apps just got easier

Jon Markoff
Android Developers
Published in
4 min readDec 3, 2018
Illustration by Virginia Poltrack

Whether your organization has 5 apps or 100, there are tools available to help automate the process of managing all of the Play Store listings. Google Play has a developer API which enables management of Play store listings, APKs, and more. In January 2017 Google acquired the developer tool suite Fabric from Twitter, as part of this acquisition was fastlane, a suite of app automation tools. fastlane can automate screenshots, manage beta deployments, and sign/push apps to the Play store.

Additionally, the Custom App Publishing API enables Managed Google Play users to create private hosted apps without a minimum version check. Managed Google Play is a marketplace for Android Enterprise that adds support for private apps. Private apps are Android apps that are distributed only to internal users and not publicly available. Private app deployments are available within minutes of creation. A fastlane pull request, built by Jan Piotrowski, a core contributor was built to allow for a code-free method of deployment. History on the feature request is in this github issue here. For more background on Managed Google Play and Google Play Protect, please see this blog post.

Why this is important: The Custom App Publishing API or fastlane greatly simplifies and reduces the friction of migrating to Managed Google Play and integrates into continuous integration tools and processes.

Setup

Important: Make sure to use the following best practices for app signing when creating debug and production keystores. Do not lose your production keystore! Once it has been used with an application id on Google Play (including private apps), you cannot change the keystore without creating a new application listing and modifying the application id.

Recommended: Utilize Google Play App Signing to sign your APKs. This is a safe option to make sure that your keystore will not be lost. Please see the implementation details here.

Important: All apps (including private apps) on Google Play must have a unique application id and cannot be reused.

When publishing private apps, there are 3 steps you need to take before this is available.

Please follow the Setup Instructions which will guide you through the following steps:

  1. Enable the Google Play Custom App Publishing API in the Cloud API Console
  2. Create a service account, download a new private key in JSON format.
  3. Enable Private Apps, instructions to follow.

fastlane setup

  • Please see this doc to install fastlane. Managed google play support is included with fastlane.

Enable Private Apps — Get the Developer Account Id

This guide shows the steps to create private apps which requires creating an OAuth callback to receive the developerAccount id. There are two methods for enabling private apps: using fastlane or using the API. Here’s how to use each and their level of difficulty:

Use fastlane — Easy

> fastlane run get_managed_play_store_publishing_rights

Example Output:

[13:20:46]: To obtain publishing rights for custom apps on Managed Play Store, open the following URL and log in:[13:20:46]: https://play.google.com/apps/publish/delegatePrivateApp?service_account=SERVICE-ACCOUNT-EMAIL.iam.gserviceaccount.com&continueUrl=https://fastlane.github.io/managed_google_play-callback/callback.html[13:20:46]: ([Cmd/Ctrl] + [Left click] lets you open this URL in many consoles/terminals/shells)[13:20:46]: After successful login you will be redirected to a page which outputs some information that is required for usage of the `create_app_on_managed_play_store` action.

Pasting the link into a web browser and authenticating with your account owner of the managed play account will send forward

Use the API — Moderate

If you don’t plan to build a web user interface for managing your apps, you can use this basic node script below and launch with Firebase functions to quickly and easily get the developerAccountId. If you don’t care, you can set the continueUrl to https://foo.bar (or another fake url) to get the developerAccountId although this is not recommended for security purposes.

Cloud Functions for Firebase setup

This guide shows how to set up cloud functions. The following code can be used for the endpoint.

functions/index.js

Create Private App Listing

Use fastlane — Easy

Example Fastfile
> fastlane create_private_app

Use the API — Moderate

API documentation. Client libraries are available in Java, Python, C#, and Ruby.

API Example

Written in Ruby, this sample code authenticates with a Google service account json keyfile and then calls the Play Custom App Service to create and upload the first version of a private APK. This code is only used for the first time an app is created, and subsequent updates should use the upload apk functionality in the Play Publishing API.

Updating Private Apps

Once a private app has been created, the Google Play Publishing API can push new APKs after the initial creation of the Play store listing. fastlane supports this feature to upload new APKs to Play, and more info can be found here.

Deployment to users

Managed Google Play requires an EMM (Enterprise Mobility Management) system to distribute apps to users. More information here.

It has never been easier to deploy and manage your private enterprise apps. Both methods of deploying apps through Managed Google Play are viable, it all comes down to you your CI system and if you want to write any code. Give fastlane a shot, and it should save you tons of time.

If you run into any issues, bugs can be filed against fastlane on github.

--

--

Jon Markoff
Android Developers

Staff Developer Advocate, Android Security & Enterprise, Google Twitter: @jonmarkoff www.jonmarkoff.com