Fastlane多Target项目中仅修改指定Target版本号与Build号的问题咨询
解决Fastlane修改指定Target版本号/Build号的问题
我之前在管理多Target的Xcode项目时也遇到过一模一样的问题——默认的increment_version_number和increment_build_number会批量修改所有Target的版本信息,这确实很头疼。给你两个最直接的解决办法:
方法1:明确指定Target参数
这两个action都支持通过target参数指定要修改的具体Target名称,同时如果你的项目有多个.xcodeproj文件,也可以加上xcodeproj参数锁定项目。修改你的lane代码如下:
desc "Archives and creates the app for the AppStore" lane :build_appstore do |options| scheme = options[:scheme] output_directory = options[:output_directory] configuration = options[:configuration] export_method = options[:export_method] bundle_id = options[:bundle_id] version = options[:version] build = options[:build] target = options[:target] # 新增:从参数传入要修改的Target名称 # 只修改指定Target的版本号 increment_version_number( version_number: version, target: target, xcodeproj: "YourProject.xcodeproj" # 如果项目路径特殊可以指定,默认会自动查找 ) # 只修改指定Target的Build号 increment_build_number( build_number: build, target: target, xcodeproj: "YourProject.xcodeproj" ) gym( scheme: scheme, output_directory: output_directory, configuration: configuration, export_method: export_method ) end
调用这个lane的时候,记得传入target参数,比如:
fastlane build_appstore scheme:"YourScheme" target:"YourTarget" version:"1.2.3" build:"45" ...
方法2:通过Info.plist路径精准锁定(补充方案)
如果你的Target对应的Info.plist路径是独立的,也可以直接指定plist_path参数,直接定位到要修改的配置文件,完全避免影响其他Target:
increment_version_number( version_number: version, plist_path: "YourProject/Targets/YourTarget/Info.plist" ) increment_build_number( build_number: build, plist_path: "YourProject/Targets/YourTarget/Info.plist" )
为什么原来的代码会修改所有Target?
默认情况下,increment_version_number和increment_build_number会遍历项目中所有的Target和它们对应的Info.plist文件,统一修改版本号。只有当你明确指定target、plist_path或者通过唯一的Bundle ID锁定时,才会只修改指定的那个Target。
内容的提问来源于stack exchange,提问作者Reimond Hill
相关产品推荐
相关产品推荐

