Skip to content

Project Dependencies

Su Ho edited this page Aug 11, 2021 · 3 revisions

Why having project's dependencies

Goal

To simplify setup for developers new to the application, as well as having a reliable build system that is also able to run past builds again in a reproducible fashion. The creation and set up of a new project will be faster and safer requiring only the language runtime (Ruby ) and dependency manager installed as prerequisites.

It always includes two basic dependencies:

  • Fastlane: is the easiest way to automate beta deployments and releases for the iOS (also Android) applications. 🚀 It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing the application.
  • Cocoapods: manages dependencies for Xcode projects. Cocoapods aims to improve the engagement with, and discoverability of, third party open-source Cocoa libraries. Developers need to specify the dependencies in a file named Podfile only. Cocoapods recursively resolves dependencies between libraries, fetches source code for all dependencies, and creates and maintains an Xcode workspace to build the project.

What we have

Bundler

  • Bundler provides a consistent environment for Ruby by tracking and installing the exact gems and versions that are needed
  • We have bundler because it manages two default dependencies we want above ( Fastlane, Cocoapods).
  • That's why we have an exactly Gemfile like below:
source "https://rubygems.org"

# Gems here
gem "fastlane"
gem "cocoapods"

Cocoapods

platform :ios, '10.0'
use_frameworks!
inhibit_all_warnings!

def testing_pods
  pod 'Quick'
  pod 'Nimble'
  pod 'Sourcery'
  pod 'OHHTTPStubs/Swift'
end

target '___PACKAGENAME___' do
  pod 'NimbleExtension', :git => 'https://github.com/nimblehq/NimbleExtension', :branch => 'master'

  pod 'SnapKit'
  pod 'Alamofire'
  pod 'R.swift'
  pod 'SwiftLint'
  
  pod 'Crashlytics'

  target 'UnitTests' do
    inherit! :search_paths
    testing_pods
  end

  target 'UITests' do
    testing_pods
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    end
  end
end

Fastlane

  • We have one Constants definition Constants.rb
  • There are three Managers for Testing and Code signing
  • Including lanes:
    1. build_for_testing
    2. unit_tests
    3. ui_tests
    4. code_signing
    5. clean_up
skip_docs

require './Constants/Constants'

require './Managers/TestManager'
require './Managers/CodeSigningManager'

test_manager = TestManager.new(
  fastlane: self
)

code_signing_manager = CodeSigningManager.new(
  fastlane: self,
  keychain_name: Constants.KEYCHAIN_NAME,
  keychain_password: Constants.DEFAULT_KEYCHAIN_PASSWORD,
  bundle_id_staging: Constants.BUNDLE_ID_STAGING,
  bundle_id_uat: Constants.BUNDLE_ID_UAT,
  bundle_id_production: Constants.BUNDLE_ID_PRODUCTION,
  dev_portal_apple_id: Constants.DEV_PORTAL_APPLE_ID,
  dev_portal_team_id: Constants.DEV_PORTAL_TEAM_ID
)

default_platform(:ios)

platform :ios do
  ### Testing ###

  desc 'build for testing'
  lane :build_for_testing do
    test_manager.build(scheme: Constants.SCHEME_NAME_TEST_SUITE)
  end

  desc 'run unit tests'
  lane :unit_tests do
    test_manager.test(scheme: Constants.SCHEME_NAME_UNIT_TESTS)
  end

  desc 'run ui tests'
  lane :ui_tests do
    test_manager.test(scheme: Constants.SCHEME_NAME_UI_TESTS)
  end

  ### Code Sign ###

  desc 'create or update certificate and provisioning profile'
  lane :code_signing do |options|
    code_signing_manager.sync_code_sign(
      update_adhoc: options.fetch(:update_adhoc, false),
      update_development: options.fetch(:update_development, false),
      update_appstore: options.fetch(:update_appstore, false)
    )
  end

  ### Utilities ###

  desc 'clean up derived data'
  lane :clean_up do
    clear_derived_data(derived_data_path: Constants.DERIVED_DATA_PATH)
  end

end

After generating

Installation

Prerequisites

  • Homebew is a free and open-source software package management system that simplifies the installation of software on Apple's macOS operating system and Linux. The name is intended to suggest the idea of building software on the Mac depending on the user's state.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Ruby
$ brew install ruby
  • Bundler
$ gem install bundler

$ bundle install

Cocoa pods installation

$ bundle exec pod install

Fastlane Usage

Code signing

$ bundle exec fastlane code_signing
  • Parameters
- update_development: Bool  # optional default is false
- update_adhoc: Bool        # optional default is false
- update_appstore: Bool     # optional default is false

Testing

$ bundle exec fastlane build_for_testing