Using react-native-config with fastlane

3.3k views Asked by At

currently in my react-native app I configure two lanes using fastlane: beta and production. I'm using react-native-config for different environment configs (stored in 2 files: .env.beta and .env.production). How can I let fastlane know which env file should be used for each lane ?

2

There are 2 answers

2
sonlexqt On BEST ANSWER

I managed to get react-native-config to pick up the correct config file using the environment variables feature provided by fastlane by using fastlane [lane] --env [beta|production].

0
Lyndsey Ferguson On

If you asking how to set environment variables before you call a command to build your app, you can do this in your Fastfile. In your Fastfile, before you call the fastlane action to build your app, set the ENV['ENVFILE'] variable to point to your .env.X file. See the react-native-config docs on environments.

lane :build_beta do
   ENV['ENVFILE'] = '.env.beta'
   build_ios_app(...) # you may be using `gym` instead.
end
lane :build_production do
   ENV['ENVFILE'] = '.env.production'
   build_ios_app(...) # you may be using `gym` instead.
end

Better yet, if the lane is exactly the same, you may want to call it with the config option from the command line:

# call me from the command line like: `fastlane build_sonlexqts_app config:beta`
lane :build_sonlexqts_app |options|
   config = options[:config]
   unless %w(beta production).include?(config)
     UI.user_error!("#{config} is invalid. Please pass either 'beta' or 'production'")
   end
   ENV['ENVFILE'] = ".env.#{config}"
   build_ios_app(...) # you may be using `gym` instead.
end