Search code examples
androidreact-nativecode-pushreact-native-code-push

How to determine if native apk / JS bundle has to be created for apps with RN >=0.60


I have been using code-push in production for more than 2 years.

How I implemented?

  • Whenever android folder of my react native app was modified, I assumed there is a native change and my CI/CD tool created a native apk file.
  • In all other cases, I generated an JS bundle and pushed via CodePush.

In the latest RN version >=0.60, we have auto-linking of native modules. Because of this, I am not able to identify if any library newly added requires a native APK to be generated or just a bundle update.

Please provide suggestion how can this be done?

Environment

react-native-code-push version: 6.0.0

react-native version: 0.61.4


Solution

  • For all those people who have similar needs. Here's what I did.

    • My app supports both android and ios, therefore whenever we add a native module it is mandatory for us to do cd ios && pod install this step will update the Podfile.lock file.
    • When the code is pushed to repo and CI/CD Pipeline is triggered, I check my git history to see if android/ or ios/ folder was updated with files.
    • If yes, I trigger my native build else I do codepush.

    Here's help on how to do conditional pipelines on Circle CI. https://medium.com/labs42/monorepo-with-circleci-conditional-workflows-69e65d3f1bd0

    FILES_CHANGED=`git diff --name-only $1 $2 | grep "android/\|ios/"`
    
    PARAMETERS='"trigger": false,'
    if [[ $FILES_CHANGED == '' ]]; then
      PARAMETERS+='"js": true'
      echo "JS Code changes detected..."
    else 
      PARAMETERS+='"native": true'
      echo "Native Code changes detected..."
    fi
    

    Above snippet of shell code helps check the files changed.