xcodebuild(xcodebuild archive)
本篇文章给大家谈谈xcodebuild,以及xcodebuild archive对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、一切都是因为懒—XCode自动打包
- 2、iOS开发知识体系之《脚本自动化打包--xcodebuild》
- 3、Xcode Build For ios Simulator arm64
- 4、xcodebuild命令详解
- 5、iOS自动构建工具 -- xcodebuild
一切都是因为懒—XCode自动打包
这是一篇关于XCode自动打包的文章以及xcodebuild, xrun两种打包方法写法。
自动打包握手悉的文章非常非常多了,我写这篇也没什么新意,只是因为有了Android那篇,所以也得有iOS的。
忽略这篇文章的名字,也是因为上篇起了这个名字。。。
其实关键只有两步,上面一大堆都是找路径和拷贝资源文件的:
其中,打包需要的证书,描述文件如果不知道在哪里看,打开xcodeproj/project.pbxproj,以文本方式打开:
CODE_SIGN_IDENTITY的地方:
因此,如果我们不用xrun打包,还有其他的方法,就是段乎使用xcodebuild exportArchive:
其中exportplist里的内容:
method是打包的类型,文档上有ad-hoc,enterprise等几种值,我这里使用的是enterprise.其他值不清楚的大家搜一下文档。
其实这几个值,也可以在shell里编译的时候自动写值,写入方法参照上面薯枯plist写入方法。
TeamID的值是DEVELOPMENT_TEAM的值:
两种方法我都测过了,都可以打包成功。
因为我不需要使用蒲公英等平台,所以其他就不介绍了。
有一点小郁闷:因为iOS打包的时候,developer和distribution的包使用的证书是不一样的,每次编译的时候,需要手动选一下证书,否则可以和android一样一键搞定,连IDE都不用打开了。
[img]iOS开发知识体系之《脚本自动化打包--xcodebuild》
iOS脚本自动化打包方案--xcodebuild
本文主要xcodebuild脚本自动化打包并上传到蒲公英或者AppStore,废话不多说,直接上干货!
先了解一下xcodebuild打包需要的一些指令
-workspace XXX.xcworkspace
XXX.xcworkspace需要编译工程的工作空间名橘轮汪称,如果工程不是.xcworkspace的,可以不需要-workspace XXX.xcworkspace这段话
-scheme XXX
XXX是工程名称,-scheme XXX是指定构建工程的名称
-configuration Release
填入打包的方式是Debug或Release,就跟在Xcode中编译前需要在Edit scheme的Build configuration中选择打出来的包是Debug还是Release包一样,-configuration就是配置编译的Build configuration
-archivePath ./myArchivePath
配置生成.xcarchive的路径, ./表示生成在当前目录下,myArchivePath是生成的.Archive文件名称
ODE_SIGN_IDENTITY=证书
配置打包的指定证书,如果该工程的Xcode已经配置好了证书,那么不加入这段话也可以,打包出来的证书就是Xcode中配置好的。
PROVISIONING_PROFILE=描述文件UUID
配置打包的描述文件,同上,Xcode已经配置好了就不用在填入这段话了
CONFIGURATION_BUILD_DIR
配置编译文件的输出路径,如果需要用到.xcarchive文件内部的dSYM等文件,可以使用改字段指定输出路径。
如果工程是勾选了Automatically manage signing,那么就不用在配置ODE_SIGN_IDENTITY和PROVISIONING_PROFILE,今天这里讲到的Automatically manage signing自动配置证书,手动配置的就不多说了,有兴趣的话可以自己研究。
xcode工程配置自动获取证书,如下图:
打包所需要文件
配置打包的ExportOptions.plist文件,可以在任意一个Xcode工程中新建一个ExportOptions.plist文件。dev和adHoc和AppStore的配置文件内容不一样,可以先手动打包后圆仔看下plist文件的样式,这里提供一个样例:
这里method对应的value为打包对应的环境,有development、ad-hoc、app-store、enterprise根据打包环境来配置不同的桐培值
编译脚本命令
xcodebuild archive -workspace XXX.xcworkspace -scheme XXX -configuration Release -archivePath ./myArchivePath CONFIGURATION_BUILD_DIR ./dir ODE_SIGN_IDENTITY=证书 PROVISIONING_PROFILE=描述文件UUID
导出ipa包命令
xcodebuild -exportArchive -archivePath ./myArchivePath.xcarchive -exportOptionsPlist ./ExportOptions.plist -exportPath ./out
-archivePath ./myArchivePath.xcarchive指定需要打包的.xcarchive路径,./myArchivePath.xcarchive表示在当前终端路径下的myArchivePath.xcarchive文件
-exportOptionsPlist ./ExportOptions.plist指定打包需要的ExportOptions.plist配置文件路径
-exportPath ./out指定打包输出的路径, ./out表示打包结果输出在终端的当前路径下的out文件家中。如果没有out文件夹会自动创建一个
脚本操作
首先:cd到需要自动打包的工程下
然后:在终端中输入touch xcodebuild.sh创建xcodebuild.sh脚本文件
然后:双击打开脚本写入下面 脚本内容(请确保所有版本的plist配置文件都写好了)
最后:在终端中输入./xcodebuild.sh运行脚本,按照步骤完成打包选择(如果运行的时候出现Permission denied,请先在终端中执行chmod a+x *.文件的后缀名后,在运行,相当于提高脚本文件的权限)
脚本内容
此脚本包含了自动上传蒲公英的选择操作,根据输入指令来执行具体操作
脚本实现
具体详细脚本见GitHub地址: 如果好用记得给star,谢谢!
如脚本打包执行遇到问题可留言沟通!
Xcode Build For ios Simulator arm64
前言
将一个老项目由Xcode11升级到Xcode12的时候,在用模拟器编译的时候,报了一个错误,具体如下:
“ld: building for iOS Simulator, but linking in dylib built for iOS, file '/Users/xxxx/Work/Git/xxx/Framework/GoogleCast/GoogleCast.framework/GoogleCast' for architecture arm64”
我使用模拟器编译的,遇到arm64的错误,一开始还是一头雾水啊。于是Google和百度就上了,经过一番查找,基本定位到问题了。
原因
下面翻译一位外国同仁的解释:
Xcode 12实际上是Apple Silicon的垫脚石,但有了这个平台,我们将得到基于arm64的macOS,模拟器也将运行在arm64架构上,而不是目前基于Intel的x86_64架构。
Xcode通常依赖于“Run Destination”来构建它的库/应用程序,所以当一个模拟器被选择为“Run Destination”时,它将为可用的模拟器架构构建应用程序,当一个设备被选择为“Run Destination”时,它将为设备支持的架构构建(arm*)。
xcodebuild,在Xcode 12+ build系统中,arm64是支持Apple Silicon的有效架构。因此,当一个模拟器被选择为运行目标时,它可能会尝试针对基于arm64的模拟器编译/链接你的库/应用程序。所以它在architecture-os-sdk-destination格式中给clang(++)发送了一些-target标志,如arm64-apple-ios13.0-simulator,clang试图构建/链接基于arm64的模卖世拟器,但最终在基于Intel的mac上失败。
但xcodebuild只在发布版本中尝试这个。因为“Build Active Architecture Only (ONLY_ACTIVE_ARCH)”构建设置通常被设置为“No”,仅用于“发布”配置。这意味着xcodebuild将尝试为选定的运行目标构建所有库/应用的架构变体。对于模拟器运行目标,它现在将包括x86_64和arm64,因为arm64在Xcode 12+中也是一个支持Apple Silicon的模拟器架构。
了解原因后,剩下来就是如何解决了。
解决方法
首先看一下Xcode11和Xcode12在Architecture配置这一块的区别:
Xcode11:中宴肢
Xcode11中有Valid Architectures的配置项。
Xcode12:
在Xcode12中,在Architecture配置组中,用Excluded Architectures代替了Valid Architectures,那么Valid Architectures跑到哪里去了,在User-Defined配置组里面。
我们的目的是能在Xcode12的模拟器上顺利编译,那么可按照下面的步骤修改:
1. 将Build Active Architecture Only配置的debug值改为Yes。如下图。
2. 如果在Xcode11中有Valid Architectures的配置项,那么请在Xcode12的User-Defined配置组里面删除Valid Architectures的配置项,同时在Target上面的Project里面的User-Defined配置组里面同样删除Valid Architectures的配置项,如何删除,选中,敲击键盘的delete就可以了。
3. 将Validate Workspace配置项修改一次,一定要变成黑粗体,默认值是NO,改成Yes就可以,或者再改回NO,反正得折腾一次。见下图。(之前有一篇文章升级Xcode12.3报错提到过这个配置,可参考一下。)
4. 配置完前三步基本就能编译通过了,如果还是报错,请尝试在Excluded Architectures的debug模式下添加arm64,如下图:
经过这几步,基本就能顺利编译通过了,不过别忘了再用真机编译试试哦,别再影响了真机祥禅测试。
结束语
个人感觉这个是Xcode12的一个坑了,不过如果所有的项目里面都采用XCFramework,估计这个问题就能屏蔽掉了。
原文链接:
xcodebuild命令详解
xcodebuild [ -project name.xcodeproj] [[ -target targetname] ... | -alltargets ] [ -configuration configurationname] [ -sdk [sdkfullpath | sdkname]] [action ...]
[buildsetting=value ...] [-userdefault=value ...]
xcodebuild [ -project name.xcodeproj] -scheme schemename [[ -destination destinationspecifier] ...] [ -destination-timeout value] [ -configuration configurationname]
[ -sdk [sdkfullpath | sdkname]] [action ...] [buildsetting=value ...] [-userdefault=value ...]
xcodebuild -workspace name.xcworkspace -scheme schemename [[ -destination destinationspecifier] ...] [ -destination-timeout value] [ -configuration configurationname]
[ -sdk [sdkfullpath | sdkname]] [action ...] [buildsetting=value ...] [-userdefault=value ...]
xcodebuild -version [ -sdk [sdkfullpath | sdkname]] [infoitem]
xcodebuild -showsdks
xcodebuild -showBuildSettings [ -project name.xcodeproj | [ -workspace name.xcworkspace -scheme schemename]]
xcodebuild -list [ -project name.xcodeproj | -workspace name.xcworkspace]
xcodebuild -exportArchive -archivePath xcarchivepath -exportPath destinationpath -exportOptionsPlist path
xcodebuild -exportLocalizations -project name.xcodeproj -localizationPath path [[ -exportLanguage language] ...]
xcodebuild -importLocalizations -project name.xcodeproj -localizationPath path
Options
-project name.xcodeproj
Build the project name.xcodeproj. Required if there are multiple project files in the same directory.
-target targetname
Build the target specified by targetname.
-alltargets
Build all the targets in the specified project.
-workspace name.xcworkspace
Build the workspace name.xcworkspace.
-scheme schemename
Build the scheme specified by schemename. Required if building a workspace.
-destination destinationspecifier
Use the destination device described by destinationspecifier. Defaults to a destination that is compatible with the selected scheme. See the Destinations section below
for more details.
-destination-timeout timeout
Use the specified timeout when searching for a destination device. The default is 30 seconds.
-configuration configurationname
Use the build configuration specified by configurationname when building each target.
-arch architecture
Use the architecture specified by architecture when building each target.
-sdk [sdkfullpath | sdkname]
Build an Xcode project or workspace against the specified SDK, using build tools appropriate for that SDK. The argument may be an absolute path to an SDK, or the canoni-
cal name of an SDK.
-showsdks
Lists all available SDKs that Xcode knows about, including their canonical names suitable for use with -sdk . Does not initiate a build.
-showBuildSettings
Lists the build settings in a project or workspace and scheme. Does not initiate a build. Use with -project or -workspace and -scheme.
-list
Lists the targets and configurations in a project, or the schemes in a workspace. Does not initiate a build. Use with -project or -workspace .
-enableAddressSanitizer [YES | NO]
Turns the address sanitizer on or off. This overrides the setting for the launch action of a scheme in a workspace.
-enableThreadSanitizer [YES | NO]
Turns the thread sanitizer on or off. This overrides the setting for the launch action of a scheme in a workspace.
-enableCodeCoverage [YES | NO]
Turns code coverage on or off during testing. This overrides the setting for the test action of a scheme in a workspace.
-derivedDataPath path
Overrides the folder that should be used for derived data when performing an action on a scheme in a workspace.
-resultBundlePath path
Writes a bundle to the specified path with results from performing an action on a scheme in a workspace.
-exportArchive
Specifies that an archive should be exported. Requires -archivePath , -exportPath , and -exportOptionsPlist . Cannot be passed along with an action.
-archivePath xcarchivepath
Specifies the path for the archive produced by the archive action, or specifies the archive that should be exported when -exportArchive is passed.
-exportPath destinationpath
Specifies the destination for the exported product, including the name of the exported file.
-exportOptionsPlist path
Specifies options for -exportArchive . xcodebuild -help can print the full set of available options.
-exportLocalizations
Exports localizations to XLIFF files. Requires -project and -localizationPath. Cannot be passed along with an action.
-importLocalizations
Imports localizations from an XLIFF file. Requires -project and -localizationPath. Cannot be passed along with an action.
-localizationPath
Specifies a path to a directory or a single XLIFF localization file.
-exportLanguage language
Specifies optional ISO 639-1 languages included in a localization export. May be repeated to specify multiple languages. May be excluded to specify an export includes only development language strings.
-xctestrun xctestrunpath
Specifies test run parameters. Can only be used with the test-without-building action. Cannot be used with -workspace or -project . See x-man-page://5/
xcodebuild.xctestrun for file format details.
-skip-testing: test-identifier, -only-testing: test-identifier
Constrain test actions. -only-testing: constrains a test action to only testing a specified identifier, and excluding all other identifiers. -skip-testing: constrains a
test action to skip testing a specified identifier, but including all other identifiers. Test identifiers have the form TestTarget[/TestClass[/TestMethod]]. An xcodebuild
command can combine multiple constraint options, but -only-testing: has precedence over -skip-testing: .
-dry-run, -n
Print the commands that would be executed, but do not execute them.
-skipUnavailableActions
Skip actions that cannot be performed instead of failing. This option is only honored if -scheme is passed.
buildsetting=value
Set the build setting buildsetting to value.
A detailed reference of Xcode build settings can be found at:
-userdefault=value
Set the user default userdefault to value.
-toolchain [identifier | name]
Use a given toolchain, specified with either an identifier or name.
-quiet
Do not print any output except for warnings and errors.
-verbose
Provide additional status output.
-version
Display version information for this install of Xcode. Does not initiate a build. When used in conjunction with -sdk , the version of the specified SDK is displayed, or
all SDKs if -sdk is given no argument. Additionally, a single line of the reported version information may be returned if infoitem is specified.
-license
Show the Xcode and SDK license agreements. Allows for accepting the license agreements without launching Xcode itself, which is useful for headless systems. Must be run
as a privileged user.
-usage
Displays usage information for xcodebuild .
The -destination option takes as its argument a destination specifier describing the device (or devices) to use as a destination. A destination specifier is a single argument
consisting of a set of comma-separated key=value pairs. The -destination option may be specified multiple times to cause xcodebuild to perform the specified action on multiple
destinations.
Destination specifiers may include the platform key to specify one of the supported destination platforms. There are additional keys which should be supplied depending on the
platform of the device you are selecting.
Some devices may take time to look up. The -destination-timeout option can be used to specify the amount of time to wait before a device is considered unavailable. If unspeci-
fied, the default timeout is 30 seconds.
Some actions (such as building) may be performed without an actual device present. To build against a platform generically instead of a specific device, the destination speci-
fier may be prefixed with the optional string "generic/", indicating that the platform should be targeted generically. An example of a generic destination is the "Generic iOS
Device" destination displayed in Xcode's UI when no physical iOS device is present.
Exporting Archives
The -exportArchive option specifies that xcodebuild should export the archive specified by -archivePath using the options specified by -exportOptionsPlist . xcodebuild -help
can print the full set of available inputs to -exportOptionsPlist . The exported product will be placed at the path specified by -exportPath .
Environment Variables
The following environment variables affect the execution of xcodebuild :
XCODE_XCCONFIG_FILE
Set to a path to a file, build settings in that file will be loaded and used when building all targets. These settings will override all other settings,
including settings passed individually on the command line, and those in the file passed with the -xcconfig option.
Exit Codes
xcodebuild exits with codes defined by sysexits(3). It will exit with EX_OK on success. On failure, it will commonly exit with EX_USAGE if any options appear malformed,
EX_NOINPUT if any input files cannot be found, EX_IOERR if any files cannot be read or written, and EX_SOFTWARE if the commands given to xcodebuild fail. It may exit with
other codes in less common scenarios.
ibtool(1), sysexits(3), xcode-select(1), xcrun(1), xed(1)
Xcode Builds Settings Reference
macOS June 20, 2016 macOS
iOS自动构建工具 -- xcodebuild
工作项目中的iOS工程都是使用Shell脚本搭配xcodebuild自动构建而成,搭配Jenkins 持续集成(CI)工具,可以很方便的实现项目的构建、部署、自动化。
xcodebuild是苹果发布自动构建的工具。它在一个Xcode项目下能构建一个或者多个闷携targets,也能在一个workspace或者Xcode项目上构建scheme。
文档描述如下:
以下是xcodebuild命令的一些参数,其中有一些参数不会执行构建命令如:
-list,-showBuildSettings, -showdestinations
-showsdks, -showTestPlans, -usage, -version.
-destination参数用于根据 destination specifier 指定特定的目标设备
当前,xcodebuild支持以下platforms
当使用 -destination参数指定大于一个目标设备时,xcodebuild 会并行在目标设备上执行测试。这个模式下,xcodebuild 自动同时的选择设备和模拟器的数目。所有可用的测试在每个目标设备上都会被执行
参数 -exportArchive 指定了xcodebuild根据 -exportOptionPlist参数发布打包到 -archivePath路径下。product 可以上传到到Apple 或者导出到本地。 导出的product 会被放在 -exportPath路径下
以下环境变量会影响xcodebuild的执行
XCODE_XCCONFIG_FILE 给一个文件设置一个路径,编译时蚂唤伏该文件中的编译设置会被链哗加载,该设置会覆盖所有其他设置
xcodebuild 退出会返回 sysexit(3) 类型。
成功 EX_OK
参数错误 EX_USAGE
输入文件未找到 EX_NOINPUT
文件无法读写 EX_IOERR
命令执行失败 EX_SOFTWARE
其他场景可能会返回其他错误码
关于xcodebuild和xcodebuild archive的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。