13

I am looking for a method that I can use to automatically publish an application to both the alpha and beta testing streams on the Google Play store, from my CI server.

My CI setup is as follows:

  1. The Android app is written using Android Studio (using Eclipse really isn't an option for us).
  2. The build scripts are written in Rake, and run the Gradle tasks, as well as Calabash-Android tests.
  3. The build server is Teamcity 8+, that is currently hosted locally (though we could be moving across to Jenkins in the cloud).

Having scanned through stackoverflow for an answer to this question, the only one found is API to automatically upload apk to Google Play? the answer to this is however over a year old, and as we all know a year is a lifetime in software development, so I hope things may have improved some what.

I also have a sub-question, after publishing to these two streams, how long should it take for testers to see them in the store? I'm hearing 24 to 48 hours, which considering apps published to production only take a couple of hours seems a little odd.

Community
  • 1
  • 1
pauljriley
  • 186
  • 1
  • 6
  • 2
    Brand-spanking-new: Google just made the publish-api available. Check the documentation @ https://developers.google.com/android-publisher/#publishing Sorry - no complete solution yet, I myself am working my way through the setup just now... – edovino Jul 30 '14 at 10:06
  • What is the status of this question? – Jared Burrows May 24 '15 at 04:46
  • @pauljriley can u share how u upload apk to play store ? – Erum Jun 15 '16 at 09:11
  • Not that I know of one, but have you looked for an Android Studio plugin for that? – rraallvv Feb 19 '17 at 18:14
  • For those who came here through a web search and just want an answer, offtopic or not: [Fastlane](https://fastlane.tools/) is a tool that automates Play Store and App Store deployments. – Thomas Jul 08 '19 at 10:28

3 Answers3

19

Edit

The plugin below no longer works because Google shut down old versions of their API. Consider using Gradle Play Publisher instead.


Update: The plugin is now available as com.savillians.gradle:android-publisher:0.4 from maven central. Add it to your buildscripts definition in build.gradle and apply it as I stated below.

I had the exact same question, and thanks to @edovino's comment and the Google Play API samples, I was able to create a gradle plugin that does the publishing to any track you wish for any flavor/variant you wish.

See the sources here: https://github.com/bluesliverx/gradle-android-publisher

I'm working on publishing this to maven central so it can be used in a build script, but for now you can grab the android-publisher subdirectory in the repo, put it in the root of your gradle build, and rename the folder to buildSrc. Use the following line in the build.gradle file for the android project you want to publish:

apply plugin: com.savillians.gradle.androidpublisher.AndroidPublisherPlugin

You can then set your publishing settings using an androidPublisher block in the build.gradle file.

android {
    ...
}
androidPublisher {
    applicationName = "Company-Name-Product-Name/1.0"
    packageName = "<package name>"
    serviceAccountEmail = "<service account email>"
    serviceAccountKeyFile = file('<p12 keyfile - NOT the json file>')
    track = "alpha" // default, don't need to specify
    variantName = "release" // default, don't need to specify
}

Make sure the service account you create has "release manager" permissions, download the p12 key file and put it in the project's directory. Then run this command:

gradle androidPublish

That will send it to Google Play using the credentials you specified. Good luck and let me know if you have questions since this is brand new.

SUPERCILEX
  • 3,929
  • 4
  • 32
  • 61
bksaville
  • 288
  • 2
  • 8
  • I'm currently trying to make use of this plugin, but the plugin and classpath configuration don't match. Says it can't find that specified plugin. – user1810737 Sep 23 '14 at 21:55
  • And how does it know which APK to use? – user1810737 Sep 23 '14 at 22:03
  • @user1810737, did you add it to the buildscripts configuration block instead of just the normal dependencies? It uses the variantName to decide which APK to get. The default of release should work fine unless you define your own variants. – bksaville Sep 24 '14 at 22:37
  • Here is a link to the [buildscript classpath docs](http://www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:external_dependencies) for gradle. – bksaville Sep 24 '14 at 23:36
  • 1
    Does the `applicationName` need to match the name in the developer console? Is it even used anywhere? – Enrico Sep 26 '14 at 21:49
  • @Enrico, The applicationName is required by the google play API and is not something the plugin uses. Honestly, I wondered how it was used myself, but it is required by the AndroidPublisher.Builder in the google API [code samples](https://github.com/googlesamples/android-play-publisher-api/blob/master/v2/java/src/com/google/play/developerapi/samples/ApplicationConfig.java). It may just be the "agent" string in the request to google, but that's just a guess. – bksaville Sep 27 '14 at 23:16
  • Thanks. The Play API docs don't shed any light on when/where is it used, but I'm sure you know that already. I'm still curious though, so if you figure it out let me know. – Enrico Sep 29 '14 at 02:34
  • Can I use this to upload a already build apk? I don't have a Gradle project yet, but would like to deploy the .apk like this for beta testing. It currenlty tells me to "apply: 'android'" and if I do, Gradle complains, that it can't build the Android project (which makes sense, because it's just a folder containing the build.gradle file, your plugin and the applications apk). – fancy Dec 08 '14 at 14:36
  • No, it does not support that and likely will not since it is a very different use case. I would download the API samples and modify them to publish your APK directly. – bksaville Dec 09 '14 at 15:25
  • @bksaville if you can help, can you answer for this: http://stackoverflow.com/questions/28560205/exception-during-publishing-app-with-savillians-gradle – Shreyash Mahajan Feb 18 '15 at 06:05
  • 3
    I would note that it's not a good idea to keep the P12 private key in your repository, as it (thanks mainly to the terrible security design of the Google Play publisher API) gives a *lot* of access to your Google Play account. If you must use this plugin, point the `serviceAccountKeyFile` parameter to a temporary path that's managed by the CI server (e.g. in Jenkins using the Credentials Binding plugin, or Build Secret plugin). – Christopher Orr Aug 17 '15 at 15:21
  • I found that instead of "release manager" for the Roles when creating the service account I needed to instead: in the Role dropdown choose "Service Accounts" -> "Service Account User" and "Service Account Token Creator" – Maks Aug 30 '18 at 01:34
5

If you're using Jenkins, the Google Play Android Publisher Plugin lets you automatically upload alpha or beta builds.

You can also use it to "promote" an APK from alpha, to beta, or from beta to a staged rollout, for example.

Multiple APK support and the ability to upload (or reuse) expansion files are included as well.

By integrating with the credentials functionality in Jenkins, the plugin can securely access your Google Play account(s) without having to check the private key in to the repository or similar.

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
0

There is now a straight forward CLI tool you can call in a build server build step:

https://github.com/codebysd/java-play-store-uploader

It uses google publisher API and uses the new JSON key format.

S.D.
  • 29,290
  • 3
  • 79
  • 130