CI/CD Android
Continuous Integration involves merging our branches to the main branch as often as possible
CODE --> UNIT TEST --> INTEGRATE
Continuous Delivery is a software development discipline where software is created in such a way that it can be launched into production at any time. There is no human interaction and only a failed test will prevent a new change in production from being implemented
CODE->UNIT TEST->INTEGRATE->ACCEPTANCE TEST->PRODUCTION DEPLOYMENT
How to upload build automatically on app center? It consist of following steps :
- Setup Android Project with build environment
- Setup Build for production release
- Create keystore file for signing the build
- Configure your app with bitbucket repository
App Center Process : Is a Azure based solution design for managing and automating the development lifecycle
- Enable BitBucket configuration with our respective repo
android { signingConfigs {
release {
storeFile file(keystore/cicddemo.jks)
storePassword 'cicddemo'
keyPassword 'cicddemo'
keyAlias = 'cicddemo'
} }
}
In AppCenter (appcenter.ms/apps)
Add New -> AppName -> Release Type(Alpha/Beta/Enterprise/Production) -> OS(Android/iOS) -> Platform(Java/Kotlin) -> Add New App
We need to add few dependencies in the gradle file. dependencies { def appCenterSdkVersion = '4.3.1' implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}" implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}" }
In MainActivity class, in onCreate(), add the following AppCenter.start(getApplication(), "{Your app secret key here}", Analytics.class, Crashes.class);
In App Center, we have options like Build, Test, Distribute, Analytics, we need to go to Build option and we get many service options like AzureDevOps, GitHub, BitBucket, Gitlab. We need to select BitBucket and Grant Access for the same. Select the project and then we need to select ConfigureBuild. Select the Build Variant, select the frequency either Build on every push or Manually choose when to run builds. We have options like Build Android App Bundle, Auto increment Version Code, Run Unit Tests, Sign Builds, Distribute Builds and then Save
Firebase App Distribution
Go to Github, Create a repository, commit the code to the repository, Go to Actions in GitHub, select Android CI. This will create an Android.yaml file. We need to edit it with our Custom Action Code.
android.yaml :
name: Build & upload to Firebase App Distribution // Name of the action
on: [push] // Whenever we push, the above action will run
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8 // Setting up the JDK version 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: build debug
run: ./gradlew assembleDebug // This used to create apk with debug flavor
- name: upload artifact to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1.2.1
with:
appId: ${{secrets.FIREBASE_APP_ID}}
token: ${{secrets.FIREBASE_TOKEN}}
groups: Debug // Name of the group we had created in Firebase Console
file: app/build/outputs/apk/debug/app-debug.apk // Path of the debug apk file
In Github Reposiory settings, select Secret, Actions and add the FIREBASE_APP_ID which we get from firebase project -> App ID
Next we need to add the FIREBASE_TOKEN
To get the token, we need to run a command in the terminal
firebase login:ci
Now we will get the token in the terminal. We need to copy that and Add it against the FIREBASE_TOKEN value
Next we need to Enable Gradle Permission from terminal
git update --chmod=+x gradlew
Then add, commit and push to the repository.
Comments
Post a Comment