React native CI-CD setup with App Center
Code Setup
1.React native config library
Run npm i react-native-config command in terminal.
2.ENV file setup
create .env file at the root level...add env variables.[Do not push the .env file with the code]
3.Android/build.gradle setup
Move to the android folder and perform the following task
cd android/app/build.gradle
Add the below line to the top of the file
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
4.Android/settings.gradle
Add following line in android/settings.gradle
include ':react-native-config
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
5.Keystore file generation
Generate .keystore key for signed building
command= keytool -genkeypair -v -keystore file-name-key.keystore -alias file-name-alias -keyalg RSA -keysize 2048 -validity 10000
On running the above command user has to provide the following details
First and last name
Organizational unit
Organization
City or locality
State or Province
Country Code (XX)
Keystore password
Key password
Do not share the above details (Especially Keystore file, key password, key store password)
6.Appcenter migration
Pass appcenter env variables into new .env file by creating .sh file in the root directory with the name
appcenter-pre-build.sh at the root level, add env variable as key and value as follow
#!/bin/bash
cd ${APPCENTER_SOURCE_DIRECTORY}
echo BASE_URL=${BASE_URL} > .env
[Note: appcenter-pre-build.sh file name shouldn’t tamper with as this is the file appcenter searches conducting build release]
App center setup
- Create a new app on the appcenter
- Provide appropriate details regarding the application like App name, release type, icon, etc... choose either android /ios and provide React native as a platform.
- On creating a new application the interface will redirect the user to a dashboard, click on the build section to select the appropriate repository among the list of services provided.
- Choose a particular branch and click on the settings button at the end of the card to configure the build.
- Build Configuration
Enter the following details carefully
- Build variant is to be set to Release
- Build frequency can be set to build at every push
- Enable the following
- Build android app gradle
- Automatically increment the version code
- Lint source code
- Provide the environment variables that are used in the code and declared in the .env file.

In case of ios generate Certificate and .mobileprovision file and upload it for signing the build process

