Categories
How To Studio

“Continuous Integration/Delivery” for Android with GitHub Actions — Part 1

Android “Continuous Integration / Delivery” Using GitHub Actions — Part 1

For French-speaking developers, this article can be found in French Here..

Dear Developers, This article will show you how to automate test execution and build of Android applications while using the github feature “GitHub Action”.

But first, what do we need to know’Continuous integration‘,’Continuous deployment‘,and’GitHub action‘Is

Sure, you’ve heard about ongoing integrations and deployments. These are two “features” that relate to a broader topic called DevOps.

by Wikipedia, Continuous integrationAlso known as CIIs a set of practices used in software engineering that validates each change in the source code to ensure that the result of the change does not generate a regression in the developed application. This concept was first introduced by GradyBooch1. Refers to, and generally refers to Extreme Programming practices. The main purpose of this practice is to detect integration issues as soon as possible during development. In addition, it automates the execution of test suites for software development. You can see the evolution. “

The following figure summarizes the features of continuous integration.

on the other hand, Continuous deployment, Or CDIs a software development strategy that automatically transfers code validation that has passed an automated test cycle to production and encourages software users to make changes. According to LeMagIT.

Therefore, CI / CD basically helps you run your project faster by automating “build”, test, and “release”. As shown in the figure below.

And developers often use tools like Jenkins, Travis CI, CircleCI, etc. to automate all of this … and recently, the newborn GitHub GitHub action..

GitHub action

It can be introduced as an Oreo production factory. There is an assembly line that goes through multiple machines to make cookies and add chocolate and cream to fully pack the Oreo pieces into the package.

For us, and for Android projects, chocolate and cream are tests and builds. And the wrapped cookie is a deliverable that is an APK file.

https://medium.com/media/a5994ef4403e4392a10c1ab5926bc954/href

Now let’s get to work. And of course, you need to have an account on GitHub.

After selecting the GitHub repository, at the top[アクション]Click the menu.

GitHub Actions makes it easy to install CI / CD in your project, creating the file “.github / Workflows /android.yml”.

https://medium.com/media/70f09d8a3b777ace6dd27ddb4f621c04/href

Each time you push, GitHub Actions will automatically launch the project build using the latest version of ubuntu, as described in the android.yml file.

Modify this file to automate unit testing and generation of APK for each push of the repository.

Unit test

The following code snippet fires every time you push the master branch. Unit tests are done using the command “bash ./gradlew test —stacktrace”.

name: Android CI/CDon:
push:
branches:
- 'master'jobs:
test:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Unit tests
run: bash ./gradlew test --stacktrace

Building an APK

The unit test is finished. Next, we’ll show you how to generate an APK that is a deliverable of your Android project.
The following code is added to the job section and the APK file “app-debug.apk” is generated and placed in “app / build / outputs / apk / debug”. And like unit tests, this process is done using Java 8 on the latest version of ubuntu.

apk:
name: Generate APK
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build debug APK
run: bash ./gradlew assembleDebug --stacktrace
- name: Upload APK
uses: actions/upload-artifact@v1
with:
name: app
path: app/build/outputs/apk/debug/app-debug.apk

And finally, “android.yml” looks like this:

https://medium.com/media/ef2c49257925caba0c42a0fad4c99971/href

And now it’s time to test what we’ve done before.

Pushing a new commit using the command prompt or Android Studio tools will start the OreoCookie production chain.

Go to the Actions in the repository to see the test and build instructions.

Build apk file:

And finally, GitHub Actions shows that the unit tests were run and the apk was generated successfully.

Then you can find and download the generated apk file. This is from the “Artif” in the upper right.

PS: If you get the following error:

Therefore, in the Android.yml file, it is enough to change the “runs-on: ubuntu-latest” line to “runs-on: windows-latest”.

And we’ll end with this first part of the tutorial.

Any questions? Memo? … On the keyboard: D


Android “Continuous Integration / Delivery” Using GitHub Actions — Part 1 Originally published ProAndroidDev In medium, people continue the conversation by emphasizing and reacting to this story.

Source

Leave a Reply

Your email address will not be published. Required fields are marked *