Conditions of use
- Make sure the Xcode command-line tool is installed
xcode-select --install
Copy the code
- Two ways to install Fastlane
# Using RubyGems
sudo gem install fastlane -NV
# Alternatively using Homebrew
brew install fastlane
Copy the code
The first step
- Initialize Fastlane in your project
Fastlane init // Swift project uses this fastlane init swiftCopy the code
Necessary function
- For me, the necessary functions are automatic packaging, and then upload to FIR or dandelion. As for those screenshots, or use match to manage certificates, they are auxiliary functions, so I will explain them in auxiliary functions.
The signature
-
Method 1: Use match for automatic management
- I will not use this here, as I will revoke the previous certificate
- Revoke existing certificates. If you want to use match to manage certificates, see this article: [juejin.cn/post/684490…]
-
Method 2: Use the cert and Sigh methods
- Step 1: Configure the project
- Manual signature management Reference Configuration – Recommended (If you don’t use match, we recommend defining a mapping of app target to provisioning profile in your Fastfile. By defining those profiles, You can guarantee reproducible builds every time you run it.)
- You can also use Xcode’s Automatically Manage Signing feature. By default, automatic signing via xcodebuild is disabled. To enable it, Pass-allowprovisioningupdates via the export_xcargs option 🙂
-
Reference configuration for manually managing signatures – Recommended
// Official configuration reference lane :betado
build_app(
export_method: "app-store",
export_options: {
provisioningProfiles: {
"com.example.bundleid"= >"Provisioning Profile Name"."com.example.bundleid2"= >"Provisioning Profile Name 2"}}) end // set the name of the export_method to xbb_dev. If it's from the appstore, you need to use the appstore certificate; If it's ad-hoc, you need to use ad-hoc credentials. lane :betado
build_app(
export_method: "app-store",
export_options: {
provisioningProfiles: {
"com.xbks.test"= >"xbks test dis"
}
}
)
end
Copy the code
- Reference configuration for automanage signatures – there may be problems
lane :beta do
build_app(export_xcargs: "-allowProvisioningUpdates")
end
Copy the code
The second step
- To package an IPA package, use the following command to package an IPA package, test, XBKS test dis is the corresponding certificate file of appstore.
lane :beta do
build_app(
scheme: "qmuidemo",
export_method: "app-store",
export_options: {
provisioningProfiles: {
"com.xbks.test"= >"xbks test dis"
}
}
)
end
Copy the code
The third step
- Installing a plug-in
// Install fastlane add_plugin pgyerCopy the code
Refer to instructions
- Build_app () parameter that can be configured in parentheses
// With these export types, the ipA needs to be exported successfully with the corresponding certificate pairing. // app-store, ad-hoc, package, enterprise, development, developer-id export_method:"development"// If you want to use ad-hoc packaging, you need to enable the configuration Sigh (adhoc:trueOutput_name: ouput_name // Export IPA location output_directory:'/Users/coderiding/Downloads/Temp'
//
scheme: "xbb"// you can omit workspace:"xbb.xcworkspace"// If automatic signature is used, you need to configure export_xcargs:"-allowProvisioningUpdates"Export_options: {} // Whether to clear the last packing information clean:trueDebug or Release configuration:"Debug"
Copy the code
- Other commands
Fastlane releaseDev descprition:"Optimize block XX"// If you want to use ad-hoc packaging, you need to enable the configuration Sigh (adhoc:true)
Time.new.strftime("%Y%m%d%H%M%S")
get_version_number
version = get_version_number(
xcodeproj: "xbks.xcodeproj",
target: "xbks"
)
get_build_number(xcodeproj: "xbb.xcodeproj")
increment_build_number
sync_code_signing
build_app
capture_screenshots
disable_automatic_code_signing(path: "my_project.xcodeproj")
enable_automatic_code_signing(path: "my_project.xcodeproj") upload_to_testflight upload_to_app_store // invokes cert Get_provisioning_profile // Obtain the push certificate get_push_certificateCopy the code
- Command Usage Problems
- Error: Apple Generic Versioning is not enabled in this project.《《《《》》》》 In target -> Building Setting, search for current Project Version and select Apple Generic for versioning System
Auxiliary function
Function: Screenshot
- Use UITest to take screenshots
- Create a new UI Test target in your Xcode project (See the top part of this article) : First add a UITest target to the project, the specific method baidu, if there is before, directly use
- Run “fastlane snapshot init” in your project Folder: Run the fastlane snapshot init command to enable the snapshot function
- Add the./ snapshothelper. swift file to your UI Test target (You can move the file anywhere You want) : The snapshothelper. swift file will be generated in the project, and I put this file in the UITest target. The purpose of this file is to write the screenshot method class that Fasntlane wrote for you, because it is written in Swift, so if it is an OC project, You will need to add the bridge file yourself. The way to add the bridge file is to create a SWIFT file directly in the OC project. The system will automatically create the bridge file for you.
- Add a new Xcode scheme for the newly created UITest target: Add a scheme for the newly created UITest target
- Edit the scheme: Edit the scheme
- In the list on the left click “Build”, and enable the checkbox under the “Run” column for your target. Select the Build option on the left and allow the Run option in our UITest scheme on the right, checked.
- Enable the Shared box of the newly created scheme: Enable the Shared option of the UITest scheme
- (Objective C only) Add the bridging header to your test class. : If you are an OC project, you need to do this to Add the bridging file
- #import “xx-swift. h” : import the Swift header file from the location where UITest is started. Xx refers to the name of the new UITest target
- The bridging header is named after your test target with -Swift.h appended.
- In your UI Test class, click the Record button on the bottom left and Record your interaction: Click the record button to start the test, and a screenshot will be taken. The premise is that the function of screenshot is added to the UI test code. The function of screenshot is divided into startup and buried point.
- To take a screenshot, call the following between interactions: This is the screenshot buried point in the screenshot function, where you want To take a screenshot, write down the code buried point.
- Swift: snapshot(“01LoginScreen”)
- Objective C: [Snapshot snapshot:@”01LoginScreen” timeWaitingForIdle:10];
- Add the following code to your setUp() method
//Swift:
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
//Objective C:
XCUIApplication *app = [[XCUIApplication alloc] init];
[Snapshot setupSnapshot:app];
[app launch];
Copy the code
- Separate out to make a lane, perform this lane is screenshots and upload
lane :screenshots doCapture_screenshots upload_to_app_store end Each command can be executed separately fastlane Action Capture_screenshots Fastlane Action Upload_to_app_storeCopy the code
- Upload to the appstore separately
fastlane deliver
Copy the code
- Screenshot with phone frame
- This will only add a device frame around the screenshots
- If you want to upload the screenshots to the App Store, you have to provide a Framefile.json, with titles and background, otherwise the resolution of the framed screenshots doesn’t match the requirements of App Store Connect.
Brew install libpng JPEG imagemagick // Error: Mogrify: no decode Delegatefor this image format `PNG', click below to re-install Brew Uninstall Imagemagick; brew install libpng jpeg; Brew install imagemagick --build-from-source // Download the latest frameit Fastlane frameit setup // Use Lane :screenshots do capture_screenshots frame_screenshots(white: True) upload_to_app_store end // Use fastlane Action frame_screenshots alone // Execute the following code to get a set of images with a black frame Fastlane Action frameit White/silver/rose_gold //Copy the code
- Customize the title and background for the screenshot
- Advanced Screenshots
// Update the fastlane snapshot update helper fileCopy the code
- Screenshot issue
- Your Snapshot Helper file is missing, please place a copy
- Error 2: Unexpected Error occurs when uploading screenshots to appstore
Slack is introduced
- Use it to send a message when the task is complete to inform you of the result
- A Slack site is used to do this
- Xbks.slack.com/apps/new/A0…
- Sign up for an account and follow the prompts to get the WebHook URL, which is used in slack actions
// Send a separate message, where slack_URL is the WebHook URL lane :slack_message you got abovedo
slack(
message: "App successfully uploaded to iTunesConnect.",
success: true,
slack_url: "https://your slack incoming webhook url"
)
end
Copy the code
reference
- docs.fastlane.tools/
- Docs. Fastlane. Tools/getting – sta…
- Docs. Fastlane. Tools/getting – sta…
- Docs. Fastlane. Tools/codesigning…
- Docs. Fastlane. Tools/codesigning…
- www.jianshu.com/p/5d298523c…
- Docs. Fastlane. Tools/actions/command reference links
- Docs. Fastlane. Tools/plugins/ava… I used dandelion
- www.pgyer.com/doc/view/fa… Dandelion plug-in configuration
- Github.com/icyleaf/fas…
- Docs. Fastlane. Tools/actions/sla…
- Medium.com/ios-develop…