iosxcodecocoapodsfastlanefastlane-gym

How to compile an iOS project from command line


I want to assemble/compile a workspace with cocoapods on it but without:

Something like: xcodebuild assemble

I want to know if the code compiles but not generate an archive or a deployed artifact.

I tried fastlane/gym but it tries to create an archive.


Solution

  • Using xcodebuild

    You can compile a project with the following command:

    xcodebuild <path to project> -scheme <scheme name> build
    

    Because you are using cocoapods, you should compile using the workspace, instead of the project, like this:

    xcodebuild -workspace <path to workspace file> -scheme <scheme name> build
    

    If the swift version is not set in the cocoapods target there is a workaround by adding the following to your Podfile:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.1'
       end
      end
    end
    

    Using fastlane

    Another way is using build_app from fastlane, like:

    build_app(scheme: 'YourScheme',
              workspace: 'YourProject.xcworkspace',
              skip_archive: true,
              skip_package_ipa: true,
              include_bitcode: false)
    

    I prefer this way, since it makes it simpler and uses xcpretty that will print the output nicer than xcodebuild.