Continuous integration and continuous deployment (CI/CD) is a powerful software development practice that can help teams build, test, and release mobile apps faster and more reliably. In this guide, we will walk you through the steps to set up a CI/CD pipeline for your mobile applications using React Native.
You will learn about the tools and techniques you need to automate the build, test, and deployment process, as well as best practices for maximizing efficiency and quality. By the end of this guide, you will have a solid foundation for implementing CI/CD for mobile app development workflow using React Native.
Step 1: Config folder
1. Create an android project
2. Create a config folder in the root directory. Like the below image.
3. Create 3 files debug.properties, staging.properties and release.properties.
4. These files should contain constants that vary according to the environment. Like BASE_URL, API_URL, AWS ACCESS and SECRET KEYs.
5. Above created .properties files must contain two variables.
a) APPNAME and APPLICATION_ID_SUFFIX
#Application Name APPNAME = "DEV <app-name>" #Application ID Suffix APPLICATION_ID_SUFFIX = .dev API_URL = "Your URL" BUCKET_NAME = "My bucket" AWS_ACCESS_KEY = "Your access key" AWS_SECRET_KEY = "your secret key"
b) APPLICATION_ID_SUFFIX
👉 Development => .dev
👉 Staging => .staging
👉 Release => NO suffix
6. Variables declared in this file you can access it using BuildConfig class.
private final String bucketName = BuildConfig.BUCKET_NAME;
Step 2: Remove App Name From src/values/string.xml
1. Remove app name line from string.xml file.
Step 3: Edit App/build.gradle
1. Update build types.
2.Replace the build type block with the below code.
a) Adding new staging build type.
b) Read variables from the above-created properties files.
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' ext.config = getProps('../config/release.properties') ext.config.each { p -> if(p.key == "APPNAME"){ resValue "string","app_name", p.value } else if(p.key=="APPLICATION_ID_SUFFIX"){ applicationIdSuffix p.value }else buildConfigField 'String', p.key, p.value } } staging { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' ext.config = getProps('../config/staging.properties') ext.config.each { p -> if (p.key == "APPNAME") { resValue "string", "app_name", p.value.replace('"', '') } else if (p.key == "APPLICATION_ID_SUFFIX") { applicationIdSuffix p.value } else { buildConfigField 'String', p.key, p.value//.replace('"','') } } } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' ext.config = getProps('../config/dev.properties') ext.config.each { p -> if (p.key == "APPNAME") { resValue "string", "app_name", p.value } else if (p.key == "APPLICATION_ID_SUFFIX") { applicationIdSuffix p.value } else buildConfigField 'String', p.key, p.value } } }
3. Add the below function at the end of the app/build.gradle file
Which reads properties files
def getProps(path) { Properties props = new Properties() props.load(new FileInputStream(file(path))) return props }
Step 4: Create Folder Structure For Build Types
1. We want to create 3 apps for 3 build types.
2. We have to create a folder structure to keep dependencies different.
3. You can keep files that are different for build types. Such as resources, firebase, and aws files for debugging, staging, and release build types.
4. You can also keep res files that vary between different build types.
Step 5:Create releaseNotes.txt File
Create one file in the root directory and name it releaseNotes.txt
Step 6:Create App On Firebase
1. We have to create 3 projects for dev, staging and release. If we are not using any dependent service, we can create 3 apps in a single project.
2. Create an app under the firebase project.
a) For dev application id suffix => .dev
b) For staging application id suffix => .staging
3. Download googleService.json and it to the project directory as per build types [environment].
4. Enable firebase app distribution.
Note: Do not create a firebase project in your personal or demo account. Ask a devops engineer to create a firebase project if you don’t have a client account yet.
Related Read: How To Implement CI/CD For Android App Development?
Step 1: Setup
1. To try and set it up, you have to install some softwares.
2. You must have an android studio or android SDK installed.
3. Install Fastlane. [Fastlane does not support windows os]
4. Create a new branch for DevOps changes.
Step 2: Firebase Setup
1. Enable app distribution service.
2. Create a new group in the app distribution named “Internal” and “Client.” And add members to the group.
Step 3: Create Keystore Files
1. We have decided to maintain the format, so keep the names below.
a) Development => projectnameDev.jks
b) Staging => projectnameStag.jks
c) Release => projectname.jks
2. Command to generate Keystore.
keytool -genkey -alias urgidoctor -keyalg RSA -keystore urgidoctorDev.jks -keysize 2048 -validity 36500
3. The password format is Projectname@123
4. Save the details of the Keystore in the keystoredetails.txt file.
Step 4: Fastlane
Fastlane is an open-source platform aimed at simplifying Android and iOS deployment. It lets you automate every aspect of your development and release workflow.
Install:
1. Open the terminal and go to the project folder.
cd <project>
2. Initialize Fastlane or can directly jump to step 7.
fastlane init
3. Add firebase distribution plugin.
fastlane add_plugin firebase_app_distribution
4. Fastlane has the main file, which is Fastfile.
5. Open and add 3 lanes named development, staging and release.
OR
6. Download the Fastlane folder and add /replace the Fastlane folder with your folder.
7. The above folder contains Fastfile and .env files for 3 environments.
Go through all the lanes.
8. Edit Fastfile and change the Keystore details you created above for all the lanes.
9. Edit .env files.
a) Add the application id that you have saved in the firebase setup step.
10. Edit .env.development, .env.staging, .env.release files and add application id respective to the environment.
Step 5: Devops File Repository
1. Get access to the mindbowser-devops-files repo if not.
2. Create a new branch with a project name.
3. We have pre-created a folder structure decided for android. Just add/replace files for this project.
4. Create the same structure concerning this project.
Add config, Keystore and firebase files, respectively.
5. Here urgidoctor is the project name. Add your project name.
6. You can find the pre-created folder structure and files here for reference.
Step 6: Jenkins
1. Add Jenkinsfile in the root directory of the project.
2. You can download the pre-created Jenkinsfile here.
3. Points where you have to change in the above file.
👉 replace_file_folder = here, give the folder name you created in step 5. In the above image, it is ‘urgidoctor.’
👉 Slack_channel = add slack channel name
If you have a new workspace other than Mindbowser, then use this link to generate a webhook.
👉 In stage(‘download necessary files stage’), update the checkout branch name to that you created in step 5.
4. Create a new multi-branch job on Jenkins.
5. Configure as below images.
Step 1: Firebase
1. Ask DevOps engineers to add all the 3 projects to the firebase “Internal” group.
2. After that, you will get notified of each build upload via mail, or you can check it on firebase.
3. Open the firebase console.
4. Go to the app distribution section.
5. Here you can download and test it.
Step 2: Create Public link
1. The build you want to forward to the client.
a) Click on the build.
b) You can also edit release notes and send them to clients.
2. If you want to create a public link, then please click the invite links option on the console.
Note: There are three environments in use: Development, Staging, and Release. Each of these environments has its own backend, with unique app IDs, base URLs, push notifications, and Google APIs. When using the firebase database, it is important to use the correct firebase google-service.json file for the corresponding environment.
It is also necessary to update the devops engineer about any changes or updates to app building dependencies, including changes to properties files, the enabling of services that depend on keystore sha, or the addition of files to src/debug, src/release, or src/staging. If these changes are not properly communicated to the devops engineer, it may result in issues with the CI build.
Related Read: How to Implement Continuous Integration for Quality Automation in Product Engineering?
In conclusion, setting up a CI/CD for mobile apps using React Native can help teams build, test, and release their apps faster and more reliably. To do so, developers can follow the steps outlined in this guide, which include creating a config folder and environment-specific properties files, updating the app/build.gradle file, adding a signing configuration, and creating a script to automate the release process.
By utilizing these tools and techniques, teams can implement a robust and efficient CI/CD workflow for their React Native mobile app projects.
How to Effectively Hire and Manage a Remote Team of Developers.
Download NowThe Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
Mindbowser has truly been foundational in my journey from concept to design and onto that final launch phase.
CEO, KickSnap
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork