logo logo

Building Android Builds for Testers – How to Save Dev Effort?

Building Android Builds for Testers

A few years ago, when I was interviewing a candidate for an Android mobile tester role, I found most of the QA candidates are too dependent on the developer to get the Android builds. In this article, I will cover how to build different flavors of Android build on your own, and remove any required dependency with Android developers.

Are you a mobile tester? Yes! Well, how do you get the Android build from your developers?
I got so many interesting answers while interviewing the candidates, such as:

  • Developers are providing the android build via QR code, we scan QR code and builds get downloaded.
  • They used to email us, sometimes they only build and attach the same in tasks.
  • Often they used to upload in Drive/Dropbox.

Different Ways of building Android Builds

In this section, I will take you through different ways of building an android app using Android Studio. This will help you in getting an updated app for your automation which can be executed by using various automation tools such as: Appium or TestProject.

Using Android Studio to build android production non-debuggable app

Clone your android project repo using git/import the project if already downloaded.

Whenever developers make changes, they basically do in their local branches, and if there is an upcoming release they will create a release branch from the master. 

Suppose we have to create a new release branch i.e release-v1.0.0 from the master, then we will run the below commands:

git checkout master, this will checkout branch to master
git pull, this will pull all the latest commits
git checkout -b release-v1.0.0, this will create a new branch named release-v1.0.0

Now our branch is switched to release branch and we are able to see all the changes from master to this release branch. You can also use the below git command to see all the latest commits which developers pushed:

git log --oneline

Now we have to create the build from this branch which we will later use for our testing purpose. Run below Gradlew commands in the terminal: 

./gradlew build, this will build project for all environments ,runs both the assemble and check task

./gradlew clean build, this will build project complete from scratch

Once successfully completed, the build will be triggered and the same .apk can be taken from your local project path, such as the below example:

AndroidStudioProjects\MyProject\MyProject..\build\production\MyProject.apk 

Using Android Studio to build android production debuggable app

Now we will build a debuggable app from the same branch i.e release-v1.0.0. In order to achieve this, we need to make some changes inside the build.gradle properties. 

Search for the build.gradle file inside your android project, and create a variable called isDebuggable and declare:

boolean isDebuggable = project.hasProperty("debuggable").toBoolean()
android {
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
        }
        release {
            minifyEnabled true
            useProguard true

        // shrink apk

        minifyEnabled !isDebuggable      
        debuggable isDebuggable

        }
    }
}

minifyEnabled !isDebuggable: ProGuard is a tool that helps us reduce, hide, and optimize our code. It can be enabled by using the minifyEnabled option for release or debug types.

shrinkResources !isDebuggable: Reduces application size by removing unused alternative sources (images, XML, and so on) and combining duplicate resources.

To make the debuggable app we need to pass -Pdebuggable in the command line param while building and running the same command which we used to build the .apk via the terminal i.e  ./gradlew build -Pdebuggable and it will generate the debuggable .apk.

How to get the same build using Jenkins

  • To get the same build using Jenkins. Make sure the Jenkins jobs are created and configured with the same repository.  
  • Login to Jenkins.
  • Go to “Builds with Parameters” section and enter the branch name as “release-v1.0.0” and click on “Build”.

It starts triggering the build and on successful completion of the job, the desired .apk can be downloaded.   

Jenkins Build                            

I hope you’ve now learned the magic of building any builds and playing with the code.
Happy Testing 😎

About the author

Vikas Sharma

Vikas Sharma is a Lead Quality Expert at Zeta Directi. Over the course of his career, he has worked on testing different mobile applications and building automation frameworks. He was one of the masterminds behind the awesome performance of OnePlus phones.

Connect with him on LinkedIn.

Comments

47 8 comments

Leave a Reply

FacebookLinkedInTwitterEmail