How to create app file with fastlane for simulator
Asked Answered
I

7

30

I need to create with fastlane .app file (or .ipa file if it works to) which I could next drag and drop to simulator on another computer. I tried do it with gym or with xcodebuild parameters but I don't know how to do it.

For now I do it in this way:

  • In XCode I build application for simulator

  • Next I am searching app file in DerivedData (~/Library/Developer/XCode/DerivedData/Build/Products/Debug-iphonesimulator/)

  • I copy this file somewhere else

But I need do it with fastlane.

Itemize answered 1/2, 2017 at 13:20 Comment(5)
Why do you need it? Can't you simply build the app on the other computer?Hieronymus
Nope. Client lives in other country, I can't also give him source code. I share him app file for simulator, he tests on simulator, and then I send application to app store. It works perfectly but I need automate this process.Itemize
Why does he test on Simulator? Wouldn't it be better for him to test on a real device? Then you could use TestFlight/Fabric/Bitrise/other services which enable exactly that.Hieronymus
Because he wants test on Simulator. Its my client so its my boss. Maybe he has not iPhone or maybe its only his fantasy. In fact... its not my business. :)Itemize
Someone answer the question so I can award the bounty please!Agnomen
L
8

As you can found in issues at fastline repo, you can do it with gym, but maybe, it will be better if you use xcodebuild (example):

xcodebuild -configuration Debug -target targetname -arch i386 -sdk iphonesimulator10.3

Than search for ~/Library/Developer/Xcode/Archives/<date> (or where you specify with -archivePath) and inside will be xcarchive.

  1. Navigate to your .xcarchive file in the finder
  2. Right click on the .xcarchive file and select "Show Package Contents" in the popup menu
  3. The finder will switch to showing the contents of the .xcarchive file.
  4. Navigate to Products/Applications
  5. your .app will be located in Products/Applications

From here.


Here is answer, that will help you.


UPDATE: If you need to get app file from command line you can do something like this:

mv /YourXCArchiveLocation/archive.xcarchive/Products/Applications/AppName.app /YourDesiredLocation/AppName.app
Longawa answered 12/6, 2017 at 18:23 Comment(11)
It is similar to build app with XCode. I wanted add building app file to fastlane script. I tried do it also with gym but I had problems: github.com/fastlane/fastlane/issues/8081. I don't know how to do it with gym.Itemize
@PiotrWasilewicz fastline uses Ruby so try to implement exec or system to run xcodebuild.Longawa
It's not so easy (I don't know Ruby) but maybe you are right... With -archivePath I can specify any path (outside ~/Library)?Itemize
I added -archivePath with path where app file should be create but it still build in ~/Library folder.Itemize
@PiotrWasilewicz Are you sure, that you doing it right? #8723133Longawa
I use this command: xcodebuild -configuration Debug -target targetname -scheme schemename -arch i386 -sdk iphonesimulator10.3 -archivePath /path/to/appfile I don't use "archive" because I can't archive for simulator. Your link is for xcarchive not for create app file.Itemize
@PiotrWasilewicz You need to create xcarchive, because (if we writing about same app file) the app file is inside this xcarchive. In finder right-click on it and then on open. Than navigate to Products->Applications and you will see app file.Longawa
When I use this command xcodebuild -configuration Debug -target targetname -scheme schemename -arch i386 -sdk iphonesimulator10.3 -archivePath /path/to/appfile I get app file in ~/Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphonesimulator so why need I to create xcarchive? If I have to... how to do it right way? I have file.xcarchive in right location. How to get app file now (by command line)?Itemize
@PiotrWasilewicz If you have that file, that's ok. But if you need to create archive in specific directory, then you can get app file from it. See updated answer.Longawa
Ok, my boss accepted this solution (fastlane -> Ruby -> xcodebuild -> move app from xcarchive) so I do the same :)Itemize
WARNING - the name is case sensitive! use 'iphonesimulator14.3' not, 'iPhoneSimulator14.3' that is displayed when you execute the command 'xcodebuild -sdk -version' which shows the camel-case and the lowercase in ()'s after the pretty title.Twickenham
M
14

I've managed to do this with build_app:

build_app(
    scheme: scheme,
    workspace: workspace,
    configuration: build_configuration,
    derived_data_path: output_path,
    skip_package_ipa: true,
    skip_archive: true,
    destination: "generic/platform=iOS Simulator"
)

I think that you could base on that if you would like to use gym.

Mcduffie answered 25/4, 2019 at 12:46 Comment(1)
Thank you very much! Helped me to solve a problem with loading of missing assets!Employer
T
12

This is the lane that I use:

lane :generate_test_app do
    xcbuild(
        workspace: "MyApp.xcworkspace",
        scheme: "MyApp",
        configuration: "Debug",
        xcargs: "-sdk iphonesimulator SYMROOT='/var/tmp/'"
    )
end

It will leave the app in /var/tmp/Debug-iphonesimulator/MyApp.app

See also: How do I build my projects from the command line?

Tenant answered 18/4, 2018 at 13:55 Comment(0)
C
9

We got this working with the following gym invocation:

archive_path = gym(
  skip_package_ipa: true,
  destination: "platform=iOS Simulator,name=iPhone 6",
  configuration: "Debug",
  build_path: "simulator_build"
)

This will spit out an .xcarchive in the directory "simulator_build/" containing a simulator-compatible .app file.

archive_path will be the absolute path to the created .xcarchive bundle.

name= needs to match the name of an existing simulator device shown in the output of xcrun simctl list. The iPhone 6 one exists by default, so it should be a safe option.

Before dragging this file to the simulator to install it, you need to whitelist it with Gatekeeper:

spctl --add ~/project/simulator_build/Products/Applications/YourApp.app

If you forget, you'll get a "… can't be opened because it is from an unidentified developer." error when clicking the app in the simulator.

If you get "… is damaged and can't be opened. You should move it to the Trash.", something has changed about the .app since it was codesigned. Use

codesign -vvv ~/project/simulator_build/Products/Applications/YourApp.app

to see what file(s) have been added, removed, or changed since codesigning.

Cutlass answered 10/1, 2020 at 17:34 Comment(2)
Brilliant! I would only add a piece from @tomasz-wronka answer, that generic device could be specified like destination: "generic/platform=iOS Simulator"Ioneionesco
This work to me but it is calling the Metro server. Is there a way to have it with a offline bundle? Using the react-native bundle command didn't solve.Serapis
L
8

As you can found in issues at fastline repo, you can do it with gym, but maybe, it will be better if you use xcodebuild (example):

xcodebuild -configuration Debug -target targetname -arch i386 -sdk iphonesimulator10.3

Than search for ~/Library/Developer/Xcode/Archives/<date> (or where you specify with -archivePath) and inside will be xcarchive.

  1. Navigate to your .xcarchive file in the finder
  2. Right click on the .xcarchive file and select "Show Package Contents" in the popup menu
  3. The finder will switch to showing the contents of the .xcarchive file.
  4. Navigate to Products/Applications
  5. your .app will be located in Products/Applications

From here.


Here is answer, that will help you.


UPDATE: If you need to get app file from command line you can do something like this:

mv /YourXCArchiveLocation/archive.xcarchive/Products/Applications/AppName.app /YourDesiredLocation/AppName.app
Longawa answered 12/6, 2017 at 18:23 Comment(11)
It is similar to build app with XCode. I wanted add building app file to fastlane script. I tried do it also with gym but I had problems: github.com/fastlane/fastlane/issues/8081. I don't know how to do it with gym.Itemize
@PiotrWasilewicz fastline uses Ruby so try to implement exec or system to run xcodebuild.Longawa
It's not so easy (I don't know Ruby) but maybe you are right... With -archivePath I can specify any path (outside ~/Library)?Itemize
I added -archivePath with path where app file should be create but it still build in ~/Library folder.Itemize
@PiotrWasilewicz Are you sure, that you doing it right? #8723133Longawa
I use this command: xcodebuild -configuration Debug -target targetname -scheme schemename -arch i386 -sdk iphonesimulator10.3 -archivePath /path/to/appfile I don't use "archive" because I can't archive for simulator. Your link is for xcarchive not for create app file.Itemize
@PiotrWasilewicz You need to create xcarchive, because (if we writing about same app file) the app file is inside this xcarchive. In finder right-click on it and then on open. Than navigate to Products->Applications and you will see app file.Longawa
When I use this command xcodebuild -configuration Debug -target targetname -scheme schemename -arch i386 -sdk iphonesimulator10.3 -archivePath /path/to/appfile I get app file in ~/Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphonesimulator so why need I to create xcarchive? If I have to... how to do it right way? I have file.xcarchive in right location. How to get app file now (by command line)?Itemize
@PiotrWasilewicz If you have that file, that's ok. But if you need to create archive in specific directory, then you can get app file from it. See updated answer.Longawa
Ok, my boss accepted this solution (fastlane -> Ruby -> xcodebuild -> move app from xcarchive) so I do the same :)Itemize
WARNING - the name is case sensitive! use 'iphonesimulator14.3' not, 'iPhoneSimulator14.3' that is displayed when you execute the command 'xcodebuild -sdk -version' which shows the camel-case and the lowercase in ()'s after the pretty title.Twickenham
B
1

The tricky part is finding the .app dir. Here is what I use:

Dir.mktmpdir do |dir|
  xcbuild(
    workspace: "#{project_name}.xcworkspace",
    scheme: "#{project_name}",
    configuration: "Debug",
    xcargs: "-sdk iphonesimulator SYMROOT=#{dir}"
  )
  app_path = sh("find #{dir} -name *.app -type d").strip()
  sh("mv #{app_path} #{options[:output_directory]}/#{app_identifier}.app")
end
Byelaw answered 2/5, 2019 at 10:9 Comment(0)
O
1

To obtain an .app file, you need to build the app without creating an archive. You can use the following Fastlane script to create an .app file for the iPhone simulator:

lane :build_app_for_simulator do
  build_ios_app(
    workspace: "WorkspaceName.xcworkspace",
    scheme: "SchemeName",
    configuration: "Debug",
    clean: true,
    sdk: "iphonesimulator",
    build_path: "./build",
    derived_data_path: "./DerivedData",
    skip_archive: true,
    skip_package_ipa: true,
    include_symbols: false,
    include_bitcode: false,
    xcargs: "-UseModernBuildSystem=YES"
  )
end

After running this script, the built .app file will be located in the DerivedData folder that you specified in the derived_data_path parameter. You need to find the Build/Products/Debug-iphonesimulator folder inside the DerivedData folder, where your .app file will be.

Ofay answered 2/4, 2023 at 14:29 Comment(0)
H
0

Well, this works for me. Our project didn't have workspace, so use project instead. Must identify destination with iOS Simulator if you want output .app files compatible on iPhone Simulator.

build_app(
      project: "projectName.xcodeproj",
      scheme: "schemeName",
      configuration: "Dev/Stage/Production",
      skip_package_ipa: true,
      skip_archive: true,
      derived_data_path: "Derived_Data_Development/",
      destination: "generic/platform=iOS Simulator"
)

Ref: https://docs.fastlane.tools/actions/gym/#:~:text=generated%20ipa%20file-,5%20Examples,-build_app(scheme

Horology answered 22/8, 2023 at 6:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.