banner 728x90

Build a CI / CD pipeline for your Android app with AWS Services

banner 728x90

Continually build, test and deliver updates for your app to your users helps you get new features faster and with less release bugs. In an earlier blog post "Automatically build your Android app with AWS codebuild", Adrian Hall explains how you can use AWS CodeBuild to compile an Android app and publish the APK on Amazon S3.

In this blog post we add a continuous integration and continuous delivery (CI / CD) pipeline using AWS CloudFormation, AWS CodePipeline, AWS CodeBuild and AWS Device Farm. After you complete the steps in this blog, you have a working pipeline that lets you build your app, test it on real physical devices, and deliver the packaged APK file to an S3 bucket every time a change is made and pushed to the source code repository.

build a ci cd pipeline for your android app with aws services - Build a CI / CD pipeline for your Android app with AWS Services

Create an Android project with Android Studio

Let's start creating a new project with Android Studio. If you already have a project that you want to use, you can skip this step. Otherwise, follow the steps on the Android Studio website to create a project. When you select the devices you want to target, select Phone and tablet . By default, a module with the name & # 39; app & # 39; made.

Create the CI / CD pipeline using AWS CloudFormation

Our pipeline uses multiple AWS services. We use an AWS CloudFormation template to automatically make all of these resources available to us. The pipeline consists of the following:

  • A codecommit repository to store the code of the Android app.
  • A codebuild project for compiling, packaging and delivering the Android app.
  • A Device Farm project to test the Android app on real physical devices.
  • An S3 bucket to store building artifacts.
  • A code pipeline pipeline to check for changes to the codecommit repository. Then it triggers a build using CodeBuild and tests with Device Darm.
  • AWS Lambda functions for calling the Device Farm test from CodePipeline, and also for providing the Device Darm project from AWS CloudFormation

Create the CloudFormation stack by following these steps:

  1. Open the AWS CloudFormation console.
  2. Click the Create Stack button.
  3. Download the Cloudformation template from https://github.com/aws-samples/aws-code-snippets/blob/master/CloudFormation/DeviceFarm.yaml .
  4. Select Upload a template to Amazon S3 then click on Choose File and select the template you downloaded in the previous step
  5. Type a stack name (for example myapp-cicd-pipeline ).
  6. Check the default parameters and then click Next . (Note that if the app module does not have the name & # 39; app & # 39;, you need to change the AppModuleName parameter).
  7. (Optional) Set all the options you need in Options and then click Next .
  8. Select I acknowledge that AWS CloudFormation can create IAM resources. (The stack uses IAM roles for Lambda, CodeBuild and CodePipeline.)
  9. Click the button .

AWS CloudFormation makes you stack. After it is completed, the stack is in the & # 39; CREATE_COMPLETE & # 39; Click the stack in the list of CloudFormation stacks, and then click the Outputs tab in the bottom half of the screen. The stack performs two values ​​that we use in the next steps. They are CodeRepoCloneUrlHttp which contains the Git URL to which we push the code, and OutputApkUrl which contains the URL of the most recently built and tested APK file.

1516035669 937 build a ci cd pipeline for your android app with aws services - Build a CI / CD pipeline for your Android app with AWS Services

Configure the project to use CodeCommit

If your development environment has not yet been configured for AWS CodeCommit, you must follow the setup steps in the [AWSCodeCommitUserGuide to install the Git client, grant CodeCommit privileges to your IAM user, and set the embedding help. You can skip step 4 because we configure an existing project to use the Git repository.

To configure your Android project for use with CodeCommit, you must add the CodeCommit repository created by the CloudFormation stack as a Git remote control. Use the output value CodeRepoCloneUrlHttp from the previous step and execute the following command from the workspace of your project:

  git remote add codecommit  

Print the code in CodeCommit

We are now ready to send the source code for your Android app to the codecommit repository. If you do this, an execution of the code pipeline pipeline will start. A few minutes after you have pushed the code, you have a fully tested APK file in the output S3 bucket.

From the workspace of your Android app you have to check if all files have been checked in to the Git repository.

Add all files in the workspace of your app:

Make the changes to your local Git repository:

  git commit -a -m "First check of the code"  

Push the changes in the CodeCommit repository:

View the build

To view the progress of CodePipeline implementation, you must open the CodePipeline console. Locate the pipeline with the stack name of the CloudFormation stack that you created as a prefix and click on the name. From here you can view the progress of the execution of the pipeline.

The execution goes through four stages (Source, Build, Test and Deliver).

  • Source : the newest code comes from the CodeCommit repository and is packaged as a ZIP file for use in other phases.
  • Build : CodePipeline triggers a build CodeBuild to compile and package the app as an APK file.
  • Test : CodePipeline calls a Lambda function that uploads the APK file to Device Farm and performs a test on real devices.
  • Deliver : the built-in and tested APK file is delivered in the specified S3 bucket

1516035670 226 build a ci cd pipeline for your android app with aws services - Build a CI / CD pipeline for your Android app with AWS Services

You can view the test results from Device Farm from the Device Farm console. Click on the project named demo-app-devicefarm if you used the default settings when you created the stack. Otherwise, click the name of the project that you specified in the CloudFormation stack parameters. On the Automated Testing tab, a test is displayed if it is currently running or has been completed. If you do not see a test, the test phase may not yet have been carried out by CodePipeline. After the test is complete, you can view the results and also screenshots of the test.

1516035672 400 build a ci cd pipeline for your android app with aws services - Build a CI / CD pipeline for your Android app with AWS Services

The final stage of the pipeline is to deliver the artefact to Amazon S3. Open the Amazon S3 console and find the artefact bucket. As the prefix of your stack & # 39; myapp-cicd-pipeline & # 39; is, the artifact bucket has a prefix of & # 39; myapp-cicd-pipeline-artifactbucket- & # 39 ;. After the pipeline has completed the execution and the build and test phases have been successfully completed, an APK file is delivered to this S3 bucket.

The stack output from CloudFormation has an output with a key named OutputApkUrl . The value contains a URL that you can use to download the APK file directly. You can also use the URL to install the APK file on an Android device.

1516035672 102 build a ci cd pipeline for your android app with aws services - Build a CI / CD pipeline for your Android app with AWS Services

Next steps

We have automated building, testing and delivery for an Android app using AWS services. With a little work you can change the AWS CloudFormation template to also sign the app with your certificate and deliver it directly to the Google Play Store. To automate delivery to the Google Play Store, you can use tools such as fastlane. You can call these tools from CodeBuild.

About the author

This post was contributed by Vinay Selvaraj. Vinay is a consultant with AWS Professional Services that specializes in helping clients migrate to the cloud. You can contact him via Twitter at @vinayselvaraj.

banner 728x90
author
Author: 
    Script & Style Show: Episode 1: Marc Grabanski
    Script & Style Show: Episode 1: Marc Grabanski
    During this second episode of the Script
    AWS AppSync region expansion and new functions for API keys
    AWS AppSync region expansion and new functions for API keys
    AWS AppSync, a managed GraphQL service with
    What is the best time to involve your mobile app users?
    What is the best time to involve your mobile app users?
    When talking to customers about mobile analysis,
    How to make a Twitter bot with Node.js
    How to make a Twitter bot with Node.js
    Twitter bots have been in the news

    Leave a reply "Build a CI / CD pipeline for your Android app with AWS Services"

    Must read×

    Top