如果您是新手,可按详细步骤往下看
一、安装xcode命令行工具
1、xcode-select --install
xcode-select --install,如果没有安装,会弹出对话框,点击安装。如果提示xcode-select: error: command line tools are already installed, use "Software Update" to install updates表示已经安装
二、安装Fastlane
sudo gem install fastlane -NV或是brew cask install fastlane我这里使用gem安装的
注意
sudo gem install fastlane -NV或
sudo gem install fastlane
这两条如果报错
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
解决方式
brew install python3或
sudo gem install fastlane --verbose
安装完了执行fastlane --version,确认下是否安装完成和当前使用的版本号。
如下表示安装成功
fastlane installation at path:
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.123.0/bin/fastlane
-----------------------------
[✔] 🚀
fastlane 2.123.0
三、初始化Fastlane
cd到你的项目目录执行
fastlane init
弹出四个选项
[17:17:46]: What would you like to use fastlane for?
1. 📸 Automate screenshots
2. 👩✈️ Automate beta distribution to TestFlight
3. 🚀 Automate App Store distribution
4. 🛠 Manual setup - manually setup your project to automate your tasks
不了解可以参考四个链接
📸 Learn more about how to automatically generate localized App Store screenshots:
[17:46:28]: https://docs.fastlane.tools/getting-started/ios/screenshots/
[17:46:28]: 👩✈️ Learn more about distribution to beta testing services:
[17:46:28]: https://docs.fastlane.tools/getting-started/ios/beta-deployment/
[17:46:28]: 🚀 Learn more about how to automate the App Store release process:
[17:46:28]: https://docs.fastlane.tools/getting-started/ios/appstore-deployment/
[17:46:28]: 👩⚕️ Learn more about how to setup code signing with fastlane
[17:46:28]: https://docs.fastlane.tools/codesigning/getting-started/
此处我选择3
如果你的工程是用cocoapods的那么可能会提示让你勾选工程的Scheme,步骤就是打开你的xcode,点击Manage Schemes,在一堆三方库中找到你的项目Scheme,在后面的多选框中进行勾选,然后rm -rf fastlane文件夹,重新fastlane init一下就不会报错了。
接着会提示你输入开发者账号和密码。
[20:48:55]: Please enter your Apple ID developer credentials
[20:48:55]: Apple ID Username:
登录成功后
选择开发者账号
选择证书
下载App的metadata。点y等待就可以。
如果报其他错的话,一般会带有github的相似的Issues的链接,里面一般都会有解决方案。
其中metadata和screenshots分别对应App元数据和商店应用截图。
Appfile主要存放App的apple_id team_id app_identifier等信息
Deliverfile中为发布的配置信息,一般情况用不到。
Fastfile是我们最应该关注的文件,也是我们的工作文件
在fastlane/Fastfile文件里的代码如下
default_platform(:ios)
platform :ios do
desc "Push a new release build to the App Store"
lane :release do
build_app(workspace: "FindSchool.xcworkspace", scheme: "FindSchool")
upload_to_app_store
end
end
确认文件信息后执行命令开始打包
fastlane release
注意如果报错
Unable to locate Xcode. Please make sure to have Xcode installed on your machine
解决方式
sudo xcode-select --switch + 你xcode的路径
sudo xcode-select --switch + /Applications
报错Exit status: 65
The following build commands failed:
Ld /Users/lsdk/Library/Developer/Xcode/DerivedData/Loan-ahfvuzyligtoboaeccsmkarphhrz/Build/Intermediates.noindex/ArchiveIntermediates/Loan/IntermediateBuildFilesPath/Loan.build/Release-iphoneos/Loan.build/Objects-normal/armv7/Loan normal armv7
(1 failure)
▸ Compiling UIImage+colorToImage.m
▸ Compiling UIImage+RoundedCorner.m
▸ Compiling UIImage+Resize.m
▸ Compiling UIImage+ColorAtPixel.m
[17:36:48]: Exit status: 65
**xcodebuild引入了错误的平台资源**
解决方法
fastlane脚本需要xcodebuild
在终端输入
bundle exec fastlane build_ios --capture_output
报错Exit status: 70
打开项目,在buildsetting中设置bitcode为Yes
往下的时候咱们开发者账户一般设置里双重认证,在fastlane里面需要再次输入一次密码
Password (application-specific for 871200@qq.com):
进入苹果网址
https://appleid.apple.com/account/manage
点击生成密码,一般会生成一串例如这样的密码,复制在终端return
yhwy-blpm-pbaz-lhlm
到了这里
[15:00:54]: This might take a few minutes. Please don't interrupt the script.
等待即可
如果您是忘记了步骤,请看如下简易步骤
1、cd到你的项目目录执行
fastlane init
2、选择3发布到appstore
3、输入账号和密码
4、确认文件信息后执行命令开始打包
fastlane release
5、进入苹果网址,点击生成密码
https://appleid.apple.com/account/manage
使用Xcode的自动管理签名功能。默认情况下,xcodebuild禁用自动签名。要启用它,请-allowProvisioningUpdates通过以下export_xcargs选项传递
在fastlane中添加
build_app(export_xcargs: "-allowProvisioningUpdates")