Home » Android » github – How can I host an Android APK file for every pull-request, so QA can test them before merging?

github – How can I host an Android APK file for every pull-request, so QA can test them before merging?

Posted by: admin May 14, 2020 Leave a comment


In order to improve our QA workflow, we want to automatically build an APK file for each pull-request on Github so we can test it BEFORE the branch is merged. We already figured out how to build the file, but we are now wondering how to integrate this in our workflow.

It seems like most available Beta programs (e.g. Crashlytics Beta, Google Play) mostly focus on creating one beta version shortly before the release, but don’t allow hosting multiple APKs in parallel.

Here’s an example for our ideal workflow:

  1. Developer finishes coding and creates a pull-request
  2. Tests run
  3. If tests are successful, an APK is built automatically and uploaded somewhere (that’s the part we’re trying to figure out)
  4. QA takes a look at the pull-request and should be able to easily download the correct APK on their testing device
  5. If there are no issues during QA, the pull-request is merged
  6. The APK file is automatically deleted

We specifically don’t want to test the APK after the pull-request has been merged, but instead test before so less bugs pop up in our develop branch.

How to&Answers:

Actually Crashlytics allow to have several versions of APK.
Ech version can have each own Version string and of course release notes, to help QA to find correct APK.

Point 3 from question can be described in that way:
CI configured to upload build to Crashlytics.
It can be achieved by gradle task:

gradle assembleRelease crashlyticsUploadDistributionRelease

It is really useful to have special build type (pullrequest) for this case. You can specify special distribution rules via distribution groups, notifications about builds and release notes.


//example function for change log 
def getLastGitCommitMessage() {
  try {
    "git log -1 --pretty=%B".execute().text.trim()
  } catch (e) {
    'Undefined message.'

android {
  buildTypes {
    pullrequest { 
      ext.betaDistributionGroupAliases = "QA, devs"
      // notification
      ext.betaDistributionNotifications = true
      // last commit message as release notes
      ext.betaDistributionReleaseNotes = getLastGitCommitMessage()

In this case build and upload command will be like that:

gradle assemblePullrequest crashlyticsUploadDistributionPullrequest


There is a lot of ways to achieve it. But in my opinion the best way is to create next stage that will produce apk as artefact and later your QA team will be able to download apk on device and test it. As anaxad wrote you can also send apk file using mail and distribution list. But such solution will be more difficult, because you need to create task (e.g. using docker) that will send mail with apk.


Make your system the server.

After that at the time of generate APK, Give your server path.
If you do like this then every time your apk will update,
So you need to use one variable? Which will decide your apk deploy on your local server or not.

After finish your development, make it true and then your apk will copy on your local server. Then it is easily accessible to QA team.

Follow this question.

Some demo code.

debug {
   applicationVariants.all { variant ->
       variant.outputs.each { output ->
           def apk = output.outputFile;
           def newName;
           newName = apk.name.replace("-" + variant.buildType.name, "")
                   .replace(project.name, name);
           newName = newName.replace("-", "-" + version + "-" + milestone +
                   "-" + build + "-");
           output.outputFile = new File(apk.parentFile, newName);