React-native-config: Using react-native-config with fastlane

Created on 4 Oct 2018  路  4Comments  路  Source: luggit/react-native-config

Hi, 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 ?

Most helpful comment

For Android, you can specify an environment file in the gradle section using the ENVFILE property. See below.

desc "Deploy a new alpha version to the Google Play Store"
  lane :alpha do
    version_code = increment_version_code(
      gradle_file_path: "./app/build.gradle"
    )

    gradle(
      task: "assembleRelease",
      system_properties: {
        "ENVFILE": "/Users/jonathanmcaboy/Desktop/Dev/Tagg/.env.prod"
      }
    )

    supply(
      track: "alpha",
      apk: "#{lane_context[SharedValues:: GRADLE_APK_OUTPUT_PATH]}"
    )

    git_commit(
      path: "./app/build.gradle",
      message: "Fastlane Android: Released new build #{version_code} [ci skip]"
    )
  end

For ios, you can control this will at the scheme level. It should be covered in the react-native-config documentation.

All 4 comments

If you follow the instructions under the iOS section in the readme, you should be able to specify that scheme when using fastlane's gym like so:

gym( scheme: '<APP_NAME_HERE> Staging', export_method: 'app-store', ... )

Similarly for android, assuming you've done everything under the android section in the readme, you should be able to run whatever build_type you want:

gradle( project_dir: 'android', task: 'clean assemble', build_type: 'debug' ... )

@sonlexqt my comment above actually isn't totally accurate. gradle's build_type needs to be capitalized, even though your actual build_type may be lowercase. so your gradle command for your android lane would be gradle( project_dir: 'android', task: 'clean assemble', build_type: 'Debug' ... ), and gradle( project_dir: 'android', task: 'clean assemble', build_type: 'Release' ... ), assuming you have configured your project's envConfigFiles as such:

project.ext.envConfigFiles = [
    debug: ".env.development",
    release: ".env.production",
]

For Android, you can specify an environment file in the gradle section using the ENVFILE property. See below.

desc "Deploy a new alpha version to the Google Play Store"
  lane :alpha do
    version_code = increment_version_code(
      gradle_file_path: "./app/build.gradle"
    )

    gradle(
      task: "assembleRelease",
      system_properties: {
        "ENVFILE": "/Users/jonathanmcaboy/Desktop/Dev/Tagg/.env.prod"
      }
    )

    supply(
      track: "alpha",
      apk: "#{lane_context[SharedValues:: GRADLE_APK_OUTPUT_PATH]}"
    )

    git_commit(
      path: "./app/build.gradle",
      message: "Fastlane Android: Released new build #{version_code} [ci skip]"
    )
  end

For ios, you can control this will at the scheme level. It should be covered in the react-native-config documentation.

@cmcaboy any idea if the ENVFILE value works with relative path?

Edit: I will use the following for now:

default_platform(:android)

platform :android do
  desc 'Assemble release'
  lane :assemble_release do |options|
    environment = options.fetch(:environment) { 'staging' }
    env_file = File.expand_path "../../.env.#{environment}"
    gradle(
      task: 'assembleRelease',
      system_properties: {
        'ENVFILE': env_file
      }
    )
  end
end

usage: fastlane assemble_release environment:prod

Was this page helpful?
0 / 5 - 0 ratings