Skip to content

Instantly share code, notes, and snippets.

@FranDepascuali
Last active March 22, 2022 19:35
Show Gist options
  • Save FranDepascuali/bb15da103b62dcfdb9fe01ff834c44e8 to your computer and use it in GitHub Desktop.
Save FranDepascuali/bb15da103b62dcfdb9fe01ff834c44e8 to your computer and use it in GitHub Desktop.
Builds iOS app (only once) for multiple simulators.
DEFAULT_SIMULATORS = ['iPhone 5s', 'iPhone 8', 'iPhone X', 'iPhone Xʀ']
PROJECT_PATH = # Project path.
SCHEME = ... # (Your scheme)
CONFIGURATION = ... # (usually Debug or Release)
APP_ID = # Your app id. i.e: com.company.app
APP_NAME = # The output name of your app.
platform :ios do
desc "Build the app"
lane :build do
simulator_sdk_path = sh("xcrun --show-sdk-path --sdk iphonesimulator").to_s.strip()
sh("xcodebuild -configuration #{CONFIGURATION} -scheme #{SCHEME} -project #{PROJECT_PATH} -sdk #{simulator_sdk_path} build -UseModernBuildSystem=NO")
end
# Before running this lane, ensure that you built the app in Xcode first.
# Example specifying simulators: fastlane run_multiple_simulators simulators:"iPhone 5s, iPhone 8"
desc 'Run App in multiple simulators'
lane :run_multiple_simulators do |options|
simulators = options[:simulators].nil? ? DEFAULT_SIMULATORS : options[:simulators].split(',').map { |device| device.strip }
derivedDataQuery = sh "xcodebuild -project #{PROJECT_PATH} -scheme #{SCHEME} -showBuildSettings | grep -m 1 \'BUILD_DIR\' | grep -oEi \"\/.*\" | tail -1"
derived_data_path = derivedDataQuery.split.last + "/Debug-iphonesimulator/#{APP_NAME}/"
if !File.exist?(derived_data_path)
UI.error("#{derived_data_path} doesn\'t exist! Building app...")
build
end
# Launch simulator app
sh('open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/')
# First boot all simulators because it takes some seconds
simulators.each do |simulator|
begin
sh "xcrun simctl list | grep Booted | grep -w \'#{simulator}\' "
rescue
sh "xcrun simctl boot \'#{simulator}\'"
end
end
# Install and launch the app
simulators.each do |simulator|
sh("xcrun simctl install \'#{simulator}\' #{derived_data_path}")
sh("xcrun simctl launch \'#{simulator}\' #{APP_ID}")
end
end
end
@FranDepascuali
Copy link
Author

FranDepascuali commented May 29, 2019

Note: If you want to use a workspace, use
-workspace workspace-path instead of -project project-path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment