10

I have a react-native app, with both ios and android directories inside a common directory. I want to be able to release (execute a lane) iOS or Android independently, so I setup fastlane init in each of the platform dirs (which created two fastlane/Fastfile in each platform dir). Android Fastfile roughly contains:

platform :android do
  lane: release_android do
    ...
  end

AND iOS:

platform :ios do
  lane: release_ios do
    ...
  end

Now I also manually created a fastlane/Fastfile file in the common containing dir that looks like this:

import '../ios/fastlane/Fastfile'
import '../android/fastlane/Fastfile'

lane :release_all do
  release_android
  release_ios
end

However, when I run fastlane release_all from the main dir, it breaks with Could not find action or lane 'release_android'.

Any idea what I'm doing wrong here? Could it not be possible to call a platform-specific lane from a general lane?

Environment

fastlane 1.96.0

3 Answers 3

5

This isn't the ideal solution as it ends up wrapping your lane execution in another lane but we do this in your equivalent to release_all, however I wonder if it would allow running those in parallel:

sh "fastlane ios beta"
sh "fastlane android beta"
4
  • Good workaround! I wonder if recent Fastlane updates enable it properly
    – mllm
    Commented Oct 18, 2016 at 14:31
  • This is not the best solution, as when using 2FA your lane will hang because it is running in non-interactive mode. Unfortunately, I don't have a solution to this, instead of using a single Fastfile. Commented Jul 3, 2020 at 10:00
  • 1
    @LukeBrandonFarrell the answer is to have your AppleStore account admin or account holder create an api key for you. Google has a comparable solution.
    – airtonix
    Commented Feb 27, 2021 at 3:48
  • Yeah makes sense. A key can get around 2FA ! Commented Feb 27, 2021 at 11:14
4

I had the same issue and after some research I found that there was an issue posted to fastlane for this exact scenario.

Instead of calling with the shell, you can use the core fastlane code to switch lanes the same way that fastlane switches lanes.

I'll post the snippet here in case the link dies.

You use the lane manager to switch to another lane, passing whatever platform, lane, params, or even env details to the specified lane.

See the source code here

An example:

lane :release_all do |options|
  Fastlane::LaneManager.cruise_lane("android", "release", options)
  Fastlane::LaneManager.cruise_lane("ios", "release", options)
end

platform :android do
  lane :release do |options|
     #do android release
  end
end

platform :ios do
  lane :release do |options|
     #do iOS release
  end
end
1
  • This should be the accepted answer. Just remember to import the platform Fastfiles at the top of your main Fastfile. Commented Aug 3, 2023 at 0:27
0

like this:

package.json

packages/fastlane/
  Fastfile
  config.yml

apps/someapp/
  package.json
  ios/
  android/
  app/
    App.tsx
    App.test.tsx
  fastlane/
    Fastfile
    config.yml

package.json

{
  "name": "yourmonorepo",
  "version": "0.0.1",
  "workspaces": [
    "apps/*",
    "packages/*"
  ],
  "scripts": {
    "app:someapp": "yarn workspace @you/someapp",
    ...
  }
}

packages/fastlane/config.yml

codesigning:
  git_url: git+ssh://[email protected]/reponame.git
  branch: master

packages/fastlane/Fastfile

fastlane_require 'config'

# this ends up always being `packages/fastlane`
HERE_DIR = File.expand_path(__dir__)
# different per app, but in the case of `someapp` it'll be `apps/someapp`
APP_ROOT = File.expand_path(File.dirname(Dir.pwd))
# the root of the repo, where your root package.json is
REPO_ROOT = File.expand_path('../..', __dir__)
STAGE_DEV = "development"
STAGE_PROD = "production"

Config.setup do |config|
    config.use_env = true
    config.env_prefix = 'YOU_FASTLANE'
    config.env_separator = '__'
    config.env_converter = :downcase
    config.env_parse_values = true
end

Settings = Config.load_files(
    "#{__dir__}/config.yml",
    "#{Dir.pwd}/config.yml"
)

APPLICATION_ID = Settings.application.id
CRYPTEX_GITURL = Settings.codesigning.git_url
CRYPTEX_BRANCH = Settings.codesigning.branch

lane :setup do
  Fastlane::LaneManager.cruise_lane(
    'ios',
    'keyfile_get',
    {
      'stage' => STAGE_DEV
    }
  )
  Fastlane::LaneManager.cruise_lane(
    'ios',
    'keystore_get',
    {
      'stage' => STAGE_DEV
    }
  )
  Fastlane::LaneManager.cruise_lane(
    'android',
    'keyfile_get',
    {
      'stage' => STAGE_DEV
    }
  )
  Fastlane::LaneManager.cruise_lane(
    'android',
    'keystore_get',
    {
      'stage' => STAGE_DEV
    }
  )
end

platform :android do
  lane :keystore_get do |options|
    stage = options[:stage] || STAGE_DEV
    UI.message("Fetched android #{stage} keystore from codesigning repo #{CRYPTEX_REPO}")
  end

  lane :keyfile_get do |options|
    stage = options[:stage] || STAGE_DEV
    UI.message("Fetched android #{stage} keyfile from codesigning repo #{CRYPTEX_REPO}")
  end

  lane :release_prod do
    # do magic here
  end
end

platform :ios do
  lane :keystore_get do |options|
    stage = options[:stage] || STAGE_DEV
    UI.message("Fetched ios #{stage} keystore from codesigning repo #{CRYPTEX_REPO}")
  end

  lane :keyfile_get do |options|
    stage = options[:stage] || STAGE_DEV
    UI.message("Fetched ios #{stage} keyfile from codesigning repo #{CRYPTEX_REPO}")
  end

  lane :release_prod do
    # do magic here
  end
end

apps/someapp/package.json

{
  "name": "@you/someapp",
  "version": "0.0.1",
  "scripts": {
    "fastlane": "fastlane"
  }
}

apps/someapp/fastlane/config.yml

application:
  id: com.you.someapp

apps/someapp/fastlane/Fastfile

$VERBOSE = nil

import '../../../packages/fastlane/Fastfile'

Now you can run :

yarn app:someapp fastlane setup

or

yarn app:someapp fastlane ios keystore_get stage:'development'
yarn app:someapp fastlane android keystore_get stage:'development'

you can even in CI do :

YOU_FASTLANE__CODESIGNING__GIT_URL=https://github.com/your/repo.git \
  yarn app:someapp fastlane ios release_prod
YOU_FASTLANE__CODESIGNING__GIT_URL=https://github.com/your/repo.git \
  yarn app:someapp fastlane android release_prod

a few extras in here:

  • yarn workspaces to facilitate monorepo
  • the ruby config gem to facilitate something better than dotenv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.