Migrating from Community CLI

  1. Install dev dependencies:

    npm
    yarn
    pnpm
    bun
    npm install @rnef/cli @rnef/plugin-metro @rnef/platform-android @rnef/platform-ios
  2. Remove @react-native-community/cli and related packages.

    npm
    yarn
    pnpm
    bun
    npm remove @react-native-community/cli @react-native-community/cli-platform-ios @react-native-community/cli-platform-android
  3. Add .rnef/ folder with caches to .gitignore:

    .gitignore
    .rnef/
  4. Add rnef.config.mjs file:

    rnef.config.mjs
    // @ts-check
    import { platformIOS } from '@rnef/platform-ios';
    import { platformAndroid } from '@rnef/platform-android';
    import { pluginMetro } from '@rnef/plugin-metro';
    
    /** @type {import('@rnef/config').Config} */
    export default {
      bundler: pluginMetro(),
      platforms: {
        ios: platformIOS(),
        android: platformAndroid(),
      },
      remoteCacheProvider: 'github-actions',
    };

    Move any project config from react-native.config.js to platform arguments in rnef.config.mjs, for example:

    react-native.config.js
    module.exports = {
      project: {
        ios: {
          sourceDir: 'custom-source',
        },
        android: {
          appName: 'custom',
        },
      },
    };

    translates to:

    rnef.config.mjs
    export default {
      platforms: {
        ios: platformIOS({ sourceDir: 'custom-source' }),
        android: platformAndroid({ appName: 'custom' }),
      },
    };
  5. Update Android files:

    In android/app/build.gradle set the cliFile with the new path:

    android/app/build.gradle
    1// cliFile = file("../../node_modules/react-native/cli.js")
    2cliFile = file("../../node_modules/@rnef/cli/dist/src/bin.js")

    In android/settings.gradle change:

    android/settings.gradle
    1// extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
    2extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand(['npx', 'rnef', 'config', '-p', 'android']) }
  6. Update iOS files:

    In ios/Podfile change:

    ios/Podfile
    1# config = use_native_modules!
    2config = use_native_modules!(['npx', 'rnef', 'config', '-p', 'ios'])

    In "Bundle React Native code and images" Build Phase in Xcode add:

    Bundle React Native code and images build phase
    1set -e
    2if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
    3source "$PODS_ROOT/../.xcode.env"
    4fi
    5if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
    6source "$PODS_ROOT/../.xcode.env.local"
    7fi
    8export CONFIG_CMD="dummy-workaround-value"
    9export CLI_PATH="$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@rnef/cli/package.json')) + '/dist/src/bin.js'")"
    10WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
  7. Cleanup native files:

    git clean -fdx ios/ android/
  8. Run new commands:

    npx rnef run:android
    npx rnef run:ios

    Additionally rename flags:

    • --mode to --variant for Android commands
    • --mode to --configuration for iOS commands
    • --buildFolder to --build-folder for iOS commands
    • --destination to --destinations for iOS commands
    • --appId to --app-id for Android commands
    • --appIdSuffix to --app-id-suffix for Android commands

    And remove unsupported flags:

    • --interactive/-i – the CLI will prompt you for input where necessary
    • --list-devices - when no devices are connected, you'll be prompt with a full device selection
  9. Configure GitHub Actions for remote builds in your workflow

    iOS:

    .github/workflows/build-ios
    - name: RNEF Remote Build - iOS simulator
      id: rnef-remote-build-ios
      uses: ./.github/actions/rnef-remote-build-ios
      with:
        destination: simulator
        github-token: ${{ secrets.GITHUB_TOKEN }}
        configuration: Debug

    Android:

    .github/workflows/build-android
    - name: RNEF Remote Build - Android
      id: rnef-remote-build-android
      uses: ./.github/actions/rnef-remote-build-android
      with:
        variant: debug
        github-token: ${{ secrets.GITHUB_TOKEN }}

    For more setup options see GitHub Actions configuration