Fastlane: Phần 1 - Cài đặt và Notes

Cài đặt#

  1. XCode Command Line Tool:
    Tải về từ trang Developer Apple, Hoặc sử dụng command
1
xcode-select --install	
  1. Script cài đặt
  • Homebrew
  • ZSH
  • Git
  • Ruby (Fastlane tương thích với version 2.4 và 2.7)
  • Fastlane, Spaceship

Tạo file scripts.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash

# Home brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# ZSH
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Git
brew install git

# Ruby
brew install ruby@2.7
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# Fastlane
sudo gem install fastlane
sudo gem install bundler
echo 'export PATH="/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# Spaceship
sudo gem install spaceship
sudo gem install pry
1
2
chmod +x scripts.sh
./scripts.sh

Nếu bị lỗi version Ruby thì có thể cài đặt Ruby 2.7.0 theo script sau:

1
2
3
4
5
6
7
8
9
10
11
12
#Install rbenv and add it to .zshrc
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
source ~/.zshrc

rbenv install 2.7.0
rbenv local 2.7.0
#or rbenv global 2.7.0 if want to set it globally
rbenv rehash

Chú ý#

  • Nếu bị lỗi Unable to locate Xcode.
    Mở XCode lên => Preferences => Locations, Select thằng Command Line Tools để nó trỏ đến XCode là được.

  • Các lệnh thường sử dụng

1
2
3
4
5
6
7
8
9
10
11
12
// Để list ra các custom lane
fastlane lanes

// Để xem các parameters có thể truyền vào hàm
fastlane actions LANES_NAME

// Chạy 1 action đã code trong Fastfile
// Ví dụ action tên là sync_all_development
fastlane sync_all_development

// --verbose Để xem chi tiết các lệnh thực thi
// -- help <= Để xem 1 action có thể làm được gì