6 Essential steps to deploy your android app

Yves KalumeYves Kalume
Oct 27, 2023·
5 min read

Before releasing your Android application, it's crucial to take proactive steps that minimize the risk of encountering bugs in production. While you can't eliminate all bugs, this article outlines key pre-deployment tasks to help you prepare your app for a successful launch.

1. Perform manual testing

Before you even think about deploying your application, you need to make sure that the version is stable enough. To do this, you can run it on a smartphone and try it out to see if all features work properly.

2. Run all your automated tests

Testing your application manually isn't really an easy task, and it's not even very efficient, since it leaves room for errors. To overcome this, make sure you have automatic tests for your application. You don't have to cover all your features with unit tests, but at the very least, make sure you've tested the main features, as well as those most likely to crash. Then, before deployment, run all your tests.

3. Enable shrinking and obfuscation

To make your app smaller and more efficient, you should enable shrinking in your release build. This will remove unnecessary code and resources, making your app lighter. Additionally, enabling shrinking also includes obfuscation, which shortens the names of your app's classes and members, and optimization, which uses smart strategies to further reduce the app's size. In essence, it's like tidying up your app's code, giving it shorter names, and making it as compact as possible. This operation is achieved thanks to R8.

android {
    buildTypes {
        getByName("release") {
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    ...
}
  • isMinifyEnbled = true enables code shrinking, obfuscation, and optimization for the project's release build type.

  • isShrinkResources = true enables resource shrinking, which is performed by the android Gradle plugin.

  • The proguard file includes the default ProGuard rules files, which can help us to customize how our code will be shrinked.

4. Run a release build on your phone

All these optimizations related to shrinking and obfuscation may create an unexpected behavior, for example If your code relies on reflection. Since obfuscated names are different from the original ones, it may break the functionality of these parts of your code.

In order to see stack trace, you can temporarily set isDebuggable=true for your release build. Don't forget to remove it after.

android {
    buildTypes {
        getByName("release") {
            isDebuggable = true
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    ...
}

Code processed by R8 is changed in various ways this can result in stack traces that don't directly match your source code, making it harder to pinpoint the exact location of an issue. Additionally, if debugging information is not preserved during obfuscation, line numbers may change, further complicating the debugging process.

To recover the original stack trace, R8 provides the retrace command-line tool, which is bundled with the command-line tools package.

To support retracing of your application's stack traces, you should ensure the build retains sufficient information to retrace with by adding the following rules to your module's proguard-rules.pro file:

-keepattributes LineNumberTable,SourceFile
-renamesourcefileattribute SourceFile

run a release build variant from android studio

Android Studio simplifies the process of selecting a build variant, with each variant corresponding to a specific buildType. To run the release build configuration, you'll need to switch to the "release" build variant.

You'll also need to include a signing configuration using your developer key.

...
android {
    ...
    defaultConfig {...}
    signingConfigs {
        // create a signingConfig for release
        create("release") {
            storeFile = file("myreleasekey.keystore")
            storePassword = "password"
            keyAlias = "MyReleaseKey"
            keyPassword = "password"
        }
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            // setting the signingConfig here
            signingConfig = signingConfigs.getByName("release")
        }
    }
}

After that, you just have to click the Run ▶ button from Android Studio

You must be careful not to version sensitive information linked to your develloper key. You can use the local.properties file and put this information in it, then read it with gradle. In the same way, you can use a plugin such as secrets-gradle-plugin.

common issues

The error I've encountered most often is related to serialization. The solution is to use annotations such as @SerialName or @SerializedName on the properties of the class in question. Or prevent the class from being modified by R8 by using the @Keep annotation on top of it.

Some third-party libraries may also cause issues. To solve them, consult library documentation for guidance, and incorporate recommended Proguard or R8 rules provided by library developers. Thorough testing of the app, especially the parts that depend on third-party libraries, is crucial to identify and resolve any obfuscation-induced issues. Additionally, seeking support from the library's developers or community can offer valuable solutions for maintaining compatibility while enhancing app security through obfuscation.

5. Create an Internal release

By conducting closed alpha or beta testing with a select group of users, you can uncover and address bugs, compatibility issues, and usability concerns before releasing the app to a wider audience. This controlled testing environment not only helps you refine the app's performance and security but also provides valuable feedback that can lead to user-centric improvements. Furthermore, it allows for a more strategic and controlled app rollout, reducing the risk of negative reviews and ensuring a smoother and more successful launch when you make the app available to the public.

6. Finally, the public release 🚀

This is a moment of both excitement and opportunity, but it also comes with important responsibilities. You'll need to prepare a compelling app listing, complete with engaging visuals, a clear description, and any necessary marketing materials to catch the attention of potential users. It's vital to consider user feedback and continuously monitor reviews and ratings after the public release, as these insights can lead to ongoing improvements.

Conclusion

The steps we've discussed are essential, but in enterprise app development, it's crucial to aim higher. Validation tests, close collaboration with QA teams, and performance benchmarking are critical. Elevating your strategy beyond the basics ensures that your app not only meets requirements but excels in a competitive environment. Embrace these additional measures to secure your app's success.

89
Subscribe to my newsletter

Read articles from Yves Kalume directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yves Kalume
Yves Kalume

Android Engineer • Google Developer Expert for Android • Open source & Rust for Fun