End-to-end CI/CD pipeline Setup with Azure DevOps for Mobile App: Android—Part 2.
I know I am late to post this second part of the End-to-End CI/CD Pipeline Setup with Azure DevOps for Mobile App series. So let's not delay and jump into the Android part of the Pipeline.
Prerequisite
a) DevOps developers have basic knowledge of manually deploying apps to the Play Store.
b) The app is already created on the Play Store with all the configuration needed to upload the build.
c) The first version of the app has already been uploaded to the Play Store, and the tester can test the app.
Let's start,
- Go to project -> Select pipeline -> New pipeline: Select “Use the classical editor.”
2. Select Azure repo git -> Repo -> Branch -> Continue.
3. Search for Android and select
4. The above step will create a default Pipeline with some jobs. We need only a few jobs out of that, as per our requirements, and delete the other job. Also, add one more job as “Play Store Release.” We will use this to deploy the app to the Play Store.
5. Select “Get Sources” and do the setup as per the screenshot below. Select the branch from which you want to create a build.
6. Create an Agent and give some name. Select MacOS and build the code on the agent machine.
7. Do gradlew setting as per the below screenshot.
8. Signing and aligning the APK file(s) **/*.apk: Before configuration for this, we must have the below files and settings on the Play Store.
a) On play store create full app with store listing detail and app icon, Android app image (else app icon issue will come, or app will not be able to upload due to some path issue), create a close build and alpha release, upload first app on play store manually.
b) Create API access USER from master play store account, give access to user of the app (else will give permission issue), give your API access USER account a owner access. This will generate one json file which we will use during build deployment.
c) Generate a keystore by CMD line not manually by android studio,
keytool -genkeypair -v -keystore sonarcloudkey.keystore -alias sonar0 -keyalg RSA -keysize 2048 -validity 10000
d) Add key store file in Library -> Secure file. Remember the key and keystore password we will use in configuration.
Do the below configuration,
9. Copy Files to: $(build.artifactstagingdirectory) ; Keep this default setting as per screenshot
10. Publish Artifact: drop: Keep this default setting as it as per screenshot
11. Release $(build.artifactstagingdirectory)/**/app-master-release.apk to internal: Before configuration for the release job create a service connection as per below screenshot by using the JSON file created during API access in step 8 -> b
Now do the setting as per the screenshot. The APK path needs to change as per branch like in the case of Master it is “$(build.artifactstagingdirectory)/**/app-master-release.apk” and for UAT it can be “$(build.artifactstagingdirectory)/**/app-uat-release.apk”
12. Change the version number or build number in Android project and commit to branch. Run the pipeline (Or set trigger action as per branch).
a) Final successful pipeline should look like this.
b) The final successful Play Store upload of IPA will look like this.
Common Error:
1. See the below screenshot for some common errors during app release,
Analysis: This issue normally appears when an APK is corrupt. The developer should take care while running NPM on a local machine. Clear the code before merging. Do not commit any file that is not needed and related to the configuration, as it will create a conflict with code running in a VM of Azure DevOps.
Solution: Clean the Android project, run the sync project with the app, run the app, and commit code to create IPA on CICD.
m -rf ./node_modules
yarn cache clean
yarn install
Cd iOS
pod cache clean — all
pod install
pod update
cd android ; ./gradlew clean ; cd ..
Thanks so much, guys!
The next Part of the series will be Sonar Cloud integration with the Azure DevOps repo.