Fastlane build numbers for Unity

Recently on a project, I came across a problem where the Fastlane Unity action I am using was blowing away the info.plist of the generated xcode project despite the Unity project being marked as “Append” instead of “Replace”.

The reason this is a problem is we wanted each build to be uploaded to hockey app with a unique build number. Fastlane has plugins to handle this but it depends on the info.plist not being destroyed.

So there’s a simple hack to fix this. Use a small ruby function in the fastlane file to write your version to a file and update each time the file is ran.

Here’s a snippet:

build_num = 1
filename = "build_number"
if File.exist?(filename)
File.open(filename) { |f|
    build_num = f.read.to_i + 1
}
end
File.open(filename, "w") { |f|
    f.write(build_num)
}

When you want to get your version number you simply just :

file = File.open("build_number", "r")
build_num = file.read
file.close

And Bob’s your uncle.

Leave a Reply

Your email address will not be published. Required fields are marked *