【发布时间】:2016-05-05 17:59:47
【问题描述】:
在某些情况下,我们需要覆盖 fastlane 的 appfile 中的值,例如使用不同的苹果账号发布应用,但官方没有记录的方式。
【问题讨论】:
在某些情况下,我们需要覆盖 fastlane 的 appfile 中的值,例如使用不同的苹果账号发布应用,但官方没有记录的方式。
【问题讨论】:
最简单的方法是使用环境变量:
像这样使用Appfile:
apple_id ENV["APPLE_ID"] || "default@company.com"
app_identifier ENV["APP_IDENTIFIER"] || "com.company.default"
当您现在在没有环境变量的情况下调用 fastlane 时:
fastlane beta
它将使用提供的默认值 (default@company.com)
设置您可以使用的不同值
APP_IDENTIFIER="com.custom.app" fastlane enterprise
正如其他回复已经指出的那样,您始终可以为不同的环境设置多个通道,只需将不同的应用标识符或用户名传递给您调用的每个操作。
【讨论】:
我们找到了一种方法,使用主项目文件夹中被忽略的 .env 文件。
它可以用来覆盖appfile中的值,如下所示:
require('dotenv')
Dotenv.load '../.env'
app_identifier "original.app.identifier" # The bundle identifier of your app
apple_id "account@example.com" # Your Apple email address
team_name "originalTeamName"
team_id "originalTeamID"
unless ENV["N42_FASTLANE_APP_IDENTIFIER"].nil?
app_identifier ENV["N42_FASTLANE_APP_IDENTIFIER"]
end
unless ENV["N42_FASTLANE_APPLE_ID"].nil?
apple_id ENV["N42_FASTLANE_APPLE_ID"]
end
unless ENV["N42_FASTLANE_TEAM_NAME"].nil?
team_name ENV["N42_FASTLANE_TEAM_NAME"]
end
unless ENV["N42_FASTLANE_TEAM_ID"].nil?
team_id ENV["N42_FASTLANE_TEAM_ID"]
end
在 .env 文件中设置新值如下:
N42_FASTLANE_APPLE_ID="anotherAccount@example.com"
【讨论】:
Dotenv.load 不是必需的,fastlane 原生支持 .env 文件。您应该使用--env 参数运行它。例如。你有一个.env.Production 文件。然后你可以像fastlane <lane_name_here> --env Production一样运行fastlane。
Appfile 支持覆盖不同通道的值:https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Appfile.md。
您还可以在Fastfile 中指定不同的team_ids、usernames 和app_identifiers,例如:
lane :example_lane do
cert(
username: "email@company.com",
team_id: "ABCDE123"
)
sigh(
username: "email@company.com",
team_id: "ABCDE123",
app_identifier: "com.company.example.app"
)
gym(
export_team_id: "ABCDE123"
)
end
【讨论】: