# Fastlane tutorial for IOS ## Fastlane là gì? **Fastlane** là một công cụ giúp việc triển khai Android và IOS trở nên dễ dàng và nhanh hơn. **Fastlane** hỗ trợ xử lý các công việc dườm dà như tạo screenshot, signing code và release ứng dụng lên store. * Xác định rõ việc deploy ứng dụng bản beta hya testing * Deploy với bất kỳ máy tính nào, kể cả CI server * Dễ dàng setup trong vài phút * Thực hiện đầy đủ các quy trình delivery sản phẩm * Tự động upload lên TestFlight, Firebase App Distribuition * Tạo thông báo sau khi upload app thành công ## Cài đặt fastlane Cài đặt fastlane trên macos ```shell= sudo gem install fastlane -NV ``` Sau khi install hoàn tất thì có thể sử dụng **fastlane** trong project ## Cài đặt fastlane cho proẹct Mở thư mục projec trên terminal, tiến hành init fastlane ```shell= fastlane init ``` Sau đó chọn lựa chọn 4 để tự cấu hình cho fastlane. Chạy xong fastlane sẽ tự động sinh ra 1 thực mục *fastlane* trong project. Trong đó chứa 2 file: *Appfile* và *Fastfile* * Appfile: đây là nơi khai báo thông tin liên quan tới build app. Nó sẽ tự động sinh ra một số trường nếu bạn chọn 1 trogn 3 option trên: * app_identifier * apple_id * itc_team_id * team_id * Fastfile: đây là file cho phép bạn viết *script* để cấu hình cho **fastlane**. Tham khảo document [Fastlane Documentation](https://docs.fastlane.tools/) ## Cấu hình fastlane Chúng ta sẽ định nghĩa 1 lane để cấu hình cho fastlane chạy ```shell= fastlane_version "2.18.3" default_platform :ios platform :ios do desc "Try to test app" lane :[name_lane] # ... code here ... end end ``` Mở **terminal** và chạy thử ```shell= fastlane name_lane ``` ### Cấu hình build app Cấu hình lane để build app trên local ```shell= lane :build_ipa do disable_automatic_code_signing( path: "Kitsbee.xcodeproj" ) build_ios_app( scheme: "Kitsbee", workspace: "Kitsbee.xcworkspace", configuration: "Release", export_method: "enterprise", output_directory: "./build/ipa", clean: true, export_options: { provisioningProfiles: { "vn.viettel.test.dev": "All app" } } ) ``` * disable auto signing trong xcodeproject * Build app ios: * **scheme**: chọn scheme cần build. Bạn cần chắc chắn scheme đã được **Shared** * **workspace**: path to workspace file * **project**: path to project file * **export_method**: phương pháp export archive. Có các phưởng pháp: app-store, ad-hoc, enterprise, developmemt,... * **output_directory**: Path thư mục lưu ipa * **clean**: Option clean trước khi build * **export_options**: Path file exportOptions.plist hoặc 1 hash các options. Sử dụng *'xcodebuild -help'* để biết các options có sẵn ### Cấu hình upload Firebase App Distribuition 1. Thêm firebase app distribuition vào fastlane project ```shell= fastlane add_plugin firebase_app_distribuition ``` 2. Xác thực Firebase Chạy lệnh để thưc hiện đăng nhập firebase ```shell= bundle exec fastlane run firebase_app_distribution_login ``` * Lệnh in ra 1 liên kết xác thực, mở liên kết trong trình duyệt. * Xác thực quyền truy cập vào Firebase dự án. Sao chép mã kết quả và gán lại vào dòng lệnh. * Lệnh sẽ in 1 thông tin mã Token mà plugin phân phối cho ứng dụg để xác thực với Firebase. * Sử udjng firebase_cli_token để thiết lập tham số cho fastlane 3. Thiết lập lane ```shell= lane :distribute do build_ios_app(...) # build_ios_app is a built-in fastlane action. firebase_app_distribution( app: "1:123456789:android:abcd1234", testers: "tester1@company.com, tester2@company.com", release_notes: "Lots of amazing new features to test out!" ) end ``` * app: ID app của bạn trên firebase * firebase_cli_token: Mã được in ra khi xác thực * release_notes/ release_notes_file: ghi chú phát hành cho bản dựng này * testers/tester_file: địa chỉ mail của tester muốn mời * groups/groups_file: nhóm tester muốn mời ## Cấu hình Diawi