DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Cross-Platform Mobile Application Development: Evaluating Flutter, React Native, HTML5, Xamarin, and Other Frameworks
  • Creating a React Native SDK: Step-By-Step Guide With Practical Examples
  • ReactJS for AI and Machine Learning: A Powerful Combination

Trending

  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  • From Zero to Production: Best Practices for Scaling LLMs in the Enterprise
  • Performing and Managing Incremental Backups Using pg_basebackup in PostgreSQL 17
  1. DZone
  2. Coding
  3. JavaScript
  4. CI/CD Pipeline With CircleCI for React Native

CI/CD Pipeline With CircleCI for React Native

This article discusses how to create CI/CD pipeline with CircleCI for React Native, which can be deployed to Android and iOS.

By 
Suthasan Jeganathan user avatar
Suthasan Jeganathan
·
Jul. 07, 23 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.9K Views

Join the DZone community and get the full member experience.

Join For Free

The CI/CD is a process that automates the build, test, and deployment. Different CI/CD (continuous integration and continuous delivery) tools are available such as Jenkins, Circle CI, and GitHub actions. 

React Native is a leading component-based mobile application framework that uses JavaScript (or typescript) to build native-like mobile applications which can be published to the Apple store and Android store.

This article briefly describes how to build a CI/CD pipeline for React Native with CircleCI. You can follow these general steps:

  1. Set up the React Native project with a version control system like GitHub, GitLab, etc. 
  2. Sign up for a CircleCI account if you don't already have one.
  3. Connect the Git repository to CircleCI. You'll need to log in to your CircleCI account, go to the "Projects" section, and click on "Add Projects." This will guide you to connect the git repo
  4. Create a CircleCI configuration file (.circleci/config.yml) in the root directory of your project. This file defines the build steps and workflows for CircleCI.
  5. Configure the build steps in the config.yml file. There are example configurations are given below for a React Native project for iOS and Android.
  6. Commit and push the .circleci/config.yml file to your repository. This triggers a build in CircleCI.
  7. CircleCI will automatically detect the configuration file and start the build process based on your defined steps. 
  8. You can monitor the build progress and view the logs within the CircleCI dashboard.
  9. Optionally, you can set up additional steps in the configuration file for running tests, generating artifacts, deploying to app stores, or any other tasks you need. 

Config.yml

The config file at .circleci/config.yml  can be used as a starting point when setting up projects or orchestrating jobs using workflows and filters through CircleCI Pipelines.

You may either maintain two different branches for iOS and Android with different config.yml or a single config.yml for both builds.

iOS

Shell
 
version: 2
jobs:
  build:
    macos:
      xcode: "14.0.0" # change the Xcode version you're using
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: |
            yarn install
      - run:
          name: Build the ios
          command: |
            yarn run react-native run-ios


Android

Shell
 
version: 2
jobs:
  build:
    working_directory: ~/repo
    docker:
      - image: circleci/android:api-29-node8-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: Install dependencies
          command: yarn install
      - save_cache:
          key: v1-dependencies-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run:
          name: Build android
          command: |
            yarn run react-native link
            yarn run react-native run-android


This example uses a CircleCI Docker image based on Android API 29 and Node.js 8. Adjust the image version according to your project requirements.

To keep both Android and iOS build jobs within the same config.yml with CircleCI workflows, follow this sample:

Shell
 
version: 2
jobs:
  build:
    macos:
      xcode: "14.0.0" #  the Xcode version you're using
    working_directory: ~/repo
    docker:
      - image: circleci/android:api-29-node8-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: Install dependencies
          command: yarn install
      - save_cache:
          key: v1-dependencies-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run:
          name: Build the app
          command: |
            yarn run react-native link
            |
            if [ "$CIRCLE_JOB" = "build-ios" ]; then
              yarn run react-native run-ios
            elif [ "$CIRCLE_JOB" = "build-android" ]; then
              yarn run react-native run-android
            fi
workflows:
  version: 2
  build:
    jobs:
      - build-ios:
          context: ios
      - build-android:
          context: android


In this case, the workflow named build has two jobs:

  •  build-ios 
  •  build-android

Users can trigger these jobs manually or set up additional configurations to trigger them automatically based on certain conditions, such as specific branches or pull requests. 

When you want to trigger a build for iOS, you can use the CircleCI API or the CircleCI web interface to start the build-ios job. Similarly, for Android, you can start the build-android job.

You can log in to the CircleCI Dashboard and go to the pipeline section to check the status as shown below:

all pipelinesNote you may get pipeline "Failed" if failures during the build process.
Disclaimer

Do not assume that the above config.yml files can be used directly. Please prepare your own config after referring CircleCI documentation mentioned under reference.

References

Pipelines

Circle CI workflows

CircleCI Job Steps

JavaScript React Native Pipeline (software) React (JavaScript library)

Opinions expressed by DZone contributors are their own.

Related

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Cross-Platform Mobile Application Development: Evaluating Flutter, React Native, HTML5, Xamarin, and Other Frameworks
  • Creating a React Native SDK: Step-By-Step Guide With Practical Examples
  • ReactJS for AI and Machine Learning: A Powerful Combination

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!