Search code examples
iosxcodereact-nativereact-native-cli

How to build react-native application with react-native cli?


I would wish to submit my react-native app to app store, but I don't know how to build it.

I've been following this official doc of react-native (http://reactnative.dev/docs/running-on-device#building-your-app-for-production) about how to build my app for production, but sadly in my case it does not quite give enough information.

Regarding building an app, the guide says this:

You can now build your app for release by tapping ⌘B or selecting Product → Build from the menu bar. Once built for release, you'll be able to distribute the app to beta testers and submit the app to the App Store.

And I can do this. But the problem is, that I need to build my app with an ENVFILE environment variable that defines where my applications configurations are read from.

With this in mind, the official guide also states:

You can also use the React Native CLI to perform this operation using the option --configuration with the value Release (e.g. npx react-native run-ios --configuration Release).

This is almost what I want. But I don't want to run my app. I just want to build it. So is there a way to build my app with the react-native cli tool? Without running it? Or could I just run it and in the process it gets build and I could find the final build in some folder then? Or if this doesn't work, could I then some way configure the ENVFILE environment variable to xcode that my app will get it?


Solution

  • The react-native-config library build can be setup like below.

    Step 1 : Create a scheme for the project you can also use the existing ones

    Step 2 : Go to edit scheme and chose pre-action under build from left menu enter image description here

    Step 3 : Provide echo '.env.yourenvironment' > /tmp/envfile in the script to run

    This will run the script in the post build and copy the values to tmpfile which will be used by the library.

    Then you can normally archive or build the project using the scheme you created.

    You can check these steps in the docs of the library as well.