Search code examples
androidiosreact-nativecontinuous-integrationapk

How to build a REACT Native app automatically using GitLab


I am looking for a way to build the APK of my React Native App automatically using a GitLab pipeline, I can't seem to find a solution on the web that does not use Expo, do you have any ideas on how to do this?

We have a team of testers who would like to test the APK on a real device, do you have any idea on how to achieve this (without Expo)?


Solution

  • Hey I've successfully automated react native build apps using gitlab CI/CD pipelines. You need to create ".gitlab-ci.yml" file in the root of your project and add below scripts and may change as per your needs.

    before_script:
      - yarn install --frozen-lockfile #--frozen-lockfile to make sure we will have the same packages version
    
    stages:
      - build
    
    build project:
      stage: build
      image: reactnativecommunity/react-native-android
      cache:
        key:
          files:
            - yarn.lock
        paths:
          - node_modules
        policy: pull #`pull` the jobs pull the cache at the beginning but do not push the changes again.
      script:
        - yarn build:apk # is the scripts defined in your package.json as "cd android #&& ./gradlew assembleRelease"
        - yarn install --pure-lockfile --cache-folder .yarn
        
      artifacts:
        paths:
          - android/app/build/outputs/apk/release/app-release.apk
    

    let me know if you have any problems