Players change phones and reinstall apps, and they expect their stars to come with them. We wanted cloud save in our new game from the first release, on both Android and iPhone, without a server and without a conflict dialog. The trick is a merge rule so simple that it fits in one line, and a shared piece of Kotlin that both platforms call.
Two stores, one format
On Android the progress lives in Play Games Saved Games. On iPhone it lives in the iCloud key-value store. They have nothing in common technically, so the shared code does not touch either. It only knows how to turn progress into a small text blob, how to read a blob back, and how to merge two of them.
The blob has one entry per line in the form key, a vertical bar, and an integer, sorted by key. Door stars, level stars, unlocked doors and one total counter go in.…