React-native-config: fastlane build ignores ENV["ENVFILE"]

Created on 2 Oct 2017  路  10Comments  路  Source: luggit/react-native-config

Running on MacOS.

So building from Android Studio or npm everything works fine. e.g.

 ENVFILE=.env.stage react-native run-android --variant=googleRelease --no-packager

However when making the builds with fastlane I can't get ENVFILE to work.
I've tried setting in terminal before running fastlane with no success

export ENVFILE=".env.production"

In fastlane I have

# Set environment file
ENV["ENVFILE"] =    ".env.production"

and building with

gradle(
  project_dir:      "android/",
  task:             "assemble",
  build_type:       "Release",
  flavor:           "google",
)

Running the app on device and checking logs the Config is empty

 ReactNativeJS: 'CONFIG', {}

Most helpful comment

@mayankbaiswar-CSE : this works for me

gradle(
      task: "assemble",
      build_type: "Release",
      system_properties: {
        "ENVFILE": ".env.staging"
      }
    )

hope it helps

All 10 comments

Ignore me :)

After a lot of testing I read the readme.md some more. The section https://github.com/luggit/react-native-config#advanced-android-setup talks about using different applicationId suffix.

So, if I want to build with ENVFILE=.env.staging, how do I achieve that with fastlane? What I have to perform with applicationIdSuffix? I cannot understand clearly in readme.md

@mayankbaiswar-CSE : this works for me

gradle(
      task: "assemble",
      build_type: "Release",
      system_properties: {
        "ENVFILE": ".env.staging"
      }
    )

hope it helps

@dtuan thanks. worked that out that time.

@dtuan @fbacker what about ios? how i can set env variables?

@Dictory have you got a solution? maybe tested using different lane for each schema?

@sheva007 yes, i have. In my fastlane config I use fastlane_require 'dotenv' and sh script. That was long time ago and i forgot which is actual now. And i have many env config files.


fastlane config

@evnName = options[:evnName]
envfile = ".env.#{@evnName}"
ENV['ENV_FILE'] = envfile
env = Dotenv.load(File.join(pathToFolder, envfile))
sh "echo '#{envfile}' > /tmp/envfile"
sh "sh ../../build-env.sh"

In fastlane config you will have access to vars as env['VAR_NAME']

build-env:

#/bin/sh

RNCDIR="./node_modules/react-native-config/ios"

if [ ! -z "$SYMROOT" ]; then
  # Ensure directories exist before copying files
  mkdir -p $SYMROOT
  mkdir -p $BUILD_DIR

  # Build dotenv
  cd $RNCDIR
  ./ReactNativeConfig/BuildDotenvConfig.ruby
  cd -

  # Copy generated dotenv files to node_modules directory
  cp "$BUILD_DIR/GeneratedInfoPlistDotEnv.h" "$RNCDIR/ReactNativeConfig/GeneratedInfoPlistDotEnv.h"
  cp "$SYMROOT/GeneratedDotEnv.m" "$RNCDIR/ReactNativeConfig/GeneratedDotEnv.m"
fi

@dtuan this does not work for me:

gradle(
      task: "assemble",
      build_type: "Release",
      system_properties: {
        "ENVFILE": ".env.staging"
      }
    )

When I print the value of the ENVFILE env var from within the build.gradle file, it does show the correct value, but the resulting .apk file does not use the values from the env file.

Any luck here, I am facing similar issues for iOS. If I use react-native CLI it works, but the build from Fastlane does not use values from the env file.

I got it working by updating the script in package.json:

"deploy:playstore": "cd android && ENVFILE=.env.test fastlane android internal && cd .."
Was this page helpful?
0 / 5 - 0 ratings