• Publishing private apps just got Easier
  • Originally by Jon Markoff
  • The Nuggets translation Project
  • Permanent link to this article: github.com/xitu/gold-m…
  • Translator: Qiuk17
  • Proofreader: PeachChou, Xiaxiayang

From illustration Virginia Poltrack

Whether you have a team of 5 or 100 apps, you can always find automated tools to help you manage your Play Store listings. Google Play allows you to manage your Play Store listings, packaged APKs, and more through its developer API. In January 2017, Google acquired a developer suite from Twitter called Fabric, which includes Fastlane that automates screenshots, manages beta deployments, signs, and pushes apps to the Play Store.

In addition, the Private App publishing API allows Google Play users with administrative rights to create and publish private apps without minimal version checking. Managed Google Play is an app store that supports proprietary applications for enterprise Android users. Private apps will only be distributed to internal users and not to the public. Private apps can be deployed within minutes of being created. Jan Piotrowski’s pull Request to Fastlane makes it possible to deploy apps with zero code. The request history for this feature can be seen here. To learn more about Managed Google Play and the Google Play project, check out this blog post.

Why this is important: Proprietary App publishing apis or Fastlane greatly simplify the migration to Managed Google Play and can be easily integrated into CI tools.

Configure private App functions

Important: When creating a keystore for debugging or production, be sure to use the best app signature. Don’t lose your keystore for production! Because once you apply it to an App ID on Google Play (including private apps), you’ll never be able to change your keystore without creating a new list of apps and changing their App ids.

Recommended: Use Google Play App Signing to sign your APK files. This is a good way to keep your keystore safe. You can see the details of this method here.

Important: All apps on Google Play (including private apps) must have a unique and non-reusable App ID.

There are only three steps you need to take before releasing your private App.

Follow the instructions in the following three steps:

  1. Enable Google Play’s private App publishing API in the Cloud API console;
  2. Create a service account and download its private key in JSON format;
  3. Enable private App function.

Configuration fastlane

  • Please read this articleThe documentTo install thefastlane. Managed Google Play support is included.

Enable private App – Get your developer account ID

This tutorial will show you how to create a private App that requires an OAuth callback to get the developer account ID. There are two ways to enable private App functionality: use Fastlane or use the API. Here’s how you can use both methods and compare their complexity:

Using Fastlane – very simple

> fastlane run get_managed_play_store_publishing_rights
Copy the code

Sample 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.
Copy the code

Paste this link into your browser to make an authorization request to the Managed Google Play account owner.

Using the API – a bit complicated

If you don’t want to create a web-based front end to manage your App, you can use the node script and Firebase features below to quickly get your developer account ID. If you don’t care about skipping urls (continueUrl), you can make it a dummy URL like foo.bar. But for safety reasons, this is not recommended.

Configure Firebase’s cloud capabilities

This guide will show you how to configure Firebase’s cloud capabilities. The following code can be used on your terminal.

const functions = require('firebase-functions');

exports.oauthcallback = functions.https.onRequest((request, response) => {
  response.send(request.query.developerAccount);
});
Copy the code

functions/index.js

Create a list of private apps

Using Fastlane – very simple

  ENV['SUPPLY_JSON_KEY'] = 'key.json'
  ENV['SUPPLY_DEVELOPER_ACCOUNT_ID'] = '111111111111000000000'
  ENV['SUPPLY_APP_TITLE'] = 'APP TITLE'
  desc "Create the private app on the Google Play store"
  lane :create_private_app do
      gradle(
        task: 'assemble',
        build_type: 'Release'
      )

      # Finds latest APK
      apk_path = Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]

      create_app_on_managed_play_store(
        json_key: ENV['SUPPLY_JSON_KEY'],
        developer_account_id: ENV['SUPPLY_DEVELOPER_ACCOUNT_ID'],
        app_title: ENV['SUPPLY_APP_TITLE'],
        language: "en_US",
        apk: apk_path
      )
    end
Copy the code

The sample Fastfile

> fastlane create_private_app
Copy the code

Using the API – a bit complicated

Perhaps you should read the API documentation first. Google provides client library files for Java, Python, C#, and Ruby.

API sample

The following Ruby code creates a private App and uploads its first version APK file by calling the Play Custom App service after authenticating with the JSON-formatted key file of the Google service account. This code should only be used when creating your App for the first time, and subsequent updates should use the upload APK feature in Google Play’s publishing API.

require "google/apis/playcustomapp_v1"

# Auth Info
KEYFILE = "KEYFILE.json" # PATH TO JSON KEYFILE
DEVELOPER_ACCOUNT = "DEVELOPER_ACCOUNT_ID" # DEVELOPER ACCOUNT ID

# App Info
APK_PATH = "FILE_NAME.apk" # PATH TO SIGNED APK WITH V1+V2 SIGNATURES
APP_TITLE = "APP TITLE"
LANGUAGE_CODE = "EN_US"

scope = "https://www.googleapis.com/auth/androidpublisher"
credentials = JSON.parse(File.open(KEYFILE, "rb").read)
authorization = Signet::OAuth2::Client.new(
 :token_credential_uri => "https://oauth2.googleapis.com/token",
 :audience => "https://oauth2.googleapis.com/token",
 :scope => scope,
 :issuer => credentials["client_id"],
 :signing_key => OpenSSL::PKey::RSA.new(credentials["private_key"], nil),
)
authorization.fetch_access_token!

custom_app = Google::Apis::PlaycustomappV1::CustomApp.new title: APP_TITLE, language_code: LANGUAGE_CODE
play_custom_apps = Google::Apis::PlaycustomappV1::PlaycustomappService.new
play_custom_apps.authorization = authorization

play_custom_apps.create_account_custom_app(
 DEVELOPER_ACCOUNT,
 custom_app,
 upload_source: APK_PATH,
) do |created_app, error|
 unless error.nil?
   puts "Error: #{error}"
 else
   puts "Success: #{created_app}."
 end
end
Copy the code

Update private App

After creating the Play Store list, once you have created a private App, you can use the Google Play Publishing API to push your new APK file. Fastlane supports this feature. You can find more information here.

Deploy to users

Managed Google Play Requires an Enterprise Mobility Management (EMM) system to distribute apps to users. To learn more, click here.

Deploying and managing enterprise private apps has never been easier. Both of these are possible ways to deploy your App using Managed Google Play. Which one to use depends on your continuous integration system and whether you want to write code. Try Fastlane, you’ll save a lot of time.

If you encounter any problems or bugs while using Fastlane, please send us an issue on Github.

If you find any mistakes in your translation or other areas that need to be improved, you are welcome to the Nuggets Translation Program to revise and PR your translation, and you can also get the corresponding reward points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.


The Nuggets Translation Project is a community that translates quality Internet technical articles from English sharing articles on nuggets. The content covers Android, iOS, front-end, back-end, blockchain, products, design, artificial intelligence and other fields. If you want to see more high-quality translation, please continue to pay attention to the Translation plan of Digging Gold, the official Weibo, Zhihu column.