Automation of releases on Android

Release automation on Android

The publication of an app in production can sometimes be a somewhat heavy process. To complete this phase it is necessary to perform a series of tasks, such as beta distribution, screenshots, translations for multi-language, APK signing, etc., which can be very laborious if it is not automated in some way. In addition when there are also different application versions (freemium, premium…) the thing gets even more tedious.

The multi-language, by the way, is one of the points that requires a lot of time and effort, when maintaining and publishing an app. Therefore, before jumping into the pool, willing to keep many languages, I suggest stopping to assess if it compensates or if on the contrary it is worth being less ambitious at this point, because if you want to do well, a new language means new translations for the app texts, new translations of title and description in the Google Play tab or in the store whatever, new translations for the app version update texts and new screenshots in the corresponding language, among other things.

Well, to avoid part of all this work, we are going to comment on things we can do to automate it. Mainly let’s comment on three points with which to automate our process of distribution and publication of an app on Android. With the help of Gradle and a series of Android libraries we are going to save ourselves a lot of time and work.

    1. Automatic Beta Distribution with Crashlytics

       

 

    1. Screenshots and icon generation for Google Play

       

 

    1. Automatic APK signing

       

 

Beta Distribution with Crashlytics

If we are using Crashlytics in our app, we can do the generation and distribution of betas automatically, simply by setting some basic configuration parameters in our file build.gradle of the app module, in the part where the build variants are defined. In this way, we parameterize the target users and the “release notes” so that when executing the command crashlyticsUploadDistributionRelease, the distribution is done automatically.

Screenshots and icon generation for Google Play

Another of the tasks that you have to go through when publishing on Google Play is to provide the corresponding icons and screenshots of our app. Google Play, requires that we provide an icon of 512 x 512 px and another of 1024 x 500 px of our app. These will be the icons that the user will see in the app finder. And it also requires that we provide at least 2 images or screenshots of our app. This, in itself, is not very expensive, but if our app has multi-language, the correct thing is to provide the corresponding icons and screenshots, since surely our app will have texts in between that will change according to the language and this is what ends up being a rather expensive job.

This is where we are going to start delegating in Espresso, the Android framework for performing user interface tests. Thanks to Espresso, to the JUnit Rules and to the bookstore Spoon, we can capture each screen of our app in the corresponding language in an automated way.

JUnit Rules

The JUnit rules, are expressed by an annotation, and serve to intercept the calls to the test method and allows us to do something before and after the invocation. In our case we are going to use a @Rule, which will make it easier for us to manage permissions to store the screenshots. Specifically we will use GrantPermissionRule, which is included in the Espresso bookstore. And one @ClassRule for the “Local” part, which will be in charge of running the test in each language we want. We will have to implement this ourselves in the following way:

Spoon Screenshots

To take screenshots, it is enough to add the gradle dependency of the Spoon client library. In order for the screenshots to be saved, your application must have the permission WRITE_EXTERNAL_STORAGE.

To make a capture at some point in the test, it’s as easy as this:

Here I show an example of UITest that makes use of JUnit and Spoon Rules to automate screenshots in 7 languages:

Automatic APK signing

And finally let’s see how to sign our APK, automatically in Android Studio since Android requires that all APKs be digitally signed with a certificate in order to be installed.

Configure the build process to automatically sign your APK

In Android Studio, you can configure your project to automatically sign the release APK during the build process by generating a signature configuration and assigning it to your release build type. A signature configuration consists of a keystore location and password, and a key alias and password. To generate a signature configuration and assign it to your release build type using Android Studio, follow these steps:

  • In the window Project, right-click on your application and then primary-click on Open Module Settings.

     

 

  • In the window Project Structure, section Modules from the left pane, click the module you want to sign.

     

 

  • Click on the tab Signing and then in Add +

     

 

  • Select the file of your keystore, enter a name for this signature configuration and the required information.

     

 

Window for creating a new signature configuration.

5. Click on the tab Build Types.

6. Click on the compilation release.

7. In Signing Config, select the settings you just created.

Selecting a signature setting in Android Studio.

8. Click on OK.

Now, every time you build your release build type using Android Studio, the IDE will automatically sign the APK with the settings you specified. You can find your signed APKs in the build/outputs/apk/ folder inside the project directory of the module you build.

Finding

The automation of tasks is basic when making distributions and publishing an app. Here we have only commented on some of them that will save us a lot of work and we have not even got to talk about Continuous Integration, a topic that we can leave for another post. It is also true that there are very powerful tools like fastlane to automate the publishing and distribution processes, but it has the drawback of not being officially compatible with all operating systems, that’s why, to write this post, I wanted to rely only on Gradle tasks and official libraries like Espresso and Spoon available for Android.

Development Outsourcing | Unreal Outsourcing

Ready to see us in action:

More To Explore

IWanta.tech
Logo
Enable registration in settings - general
Have any project in mind?

Contact us:

small_c_popup.png