Gooby is a set of puzzle games written in Rust with Dioxus, compiled to WebAssembly and served as a progressive web app by a Cloudflare Worker. You can install it from the browser, but I also wanted it in the Play Store, without writing a second app.
A Trusted Web Activity (TWA) does exactly that. It's an Android app whose only job is to open your website full screen in Chrome, with no address bar. This post covers how Gooby's TWA is built and the things that went wrong on the way. Everything here comes from the repository: the build script, the runbook and the decision log.
The wrapper is a config file
The Play Store app has the package id in.gooby.app and opens https://gooby.in/app. None of the game code is in the APK. As the runbook puts it:
Game updates ship through the website; the store build only changes when the wrapper does (icon, name, colours, package settings).
I build the Android project with Google's Bubblewrap CLI from one JSON file, twa/twa-manifest.json. These are the fields that matter most:
{
"packageId": "in.gooby.app",
"host": "gooby.in",
"display": "standalone",
"startUrl": "/app",
"fullScopeUrl": "https://gooby.in/",
"fallbackType": "customtabs",
"minSdkVersion": 24,
"orientation": "portrait",
"themeColor": "#F3F4F6",
"themeColorDark": "#0E1014",
"enableNotifications": false
}
The Gradle project Bubblewrap generates from it is git-ignored, and so are keystores, .aab and .apk files. Only the manifest, the launcher icons and the store graphics are committed. Bubblewrap can rebuild the rest whenever I need it, so there's only one place where the package id and signing keys are defined.
One script from manifest to a checked bundle
scripts/build-twa.sh does the whole build. It pins Bubblewrap with npx -y @bubblewrap/cli@1.27.0, regenerates the Android project, copies Gooby's own launcher icons over Bubblewrap's generic ones, then builds and signs.
The first gotcha was in the build output. Bubblewrap passes the keystore passwords to apksigner and jarsigner on their command lines, and when a command fails it prints that command in full. That would put the passwords in the terminal and in any log that captures it. So the script filters them out:
# Bubblewrap hands the passwords to apksigner and jarsigner on their command lines, and prints
# a failed command in full: keep them out of the output.
"${BW[@]}" build </dev/null 2>&1 | tr '\r' '\n' \
| sed -u "s/${BUBBLEWRAP_KEYSTORE_PASSWORD}/[redacted]/g; s/${BUBBLEWRAP_KEY_PASSWORD}/[redacted]/g" \
| grep -v -e DEP0190 -e trace-deprecation
After the build, the script checks the output:
- the bundle's signature verifies (
jarsigner -verify) - the APK and the bundle are signed by the same key
- that key is the first fingerprint in
twa-manifest.json - the package name, version and SDK levels are what I expect
- the launcher icon still has its themed (monochrome) layer, which Android 13 uses for themed icons and which is lost if the icon copy step is skipped
A fix that went in with the script was in the manifest itself: the version name's key is appVersion. I had appVersionName, which Bubblewrap silently ignores.
The passwords live outside the repository in an owner-only env file, and twa/android.keystore is a symlink to a keystore that sits next to it. The runbook says it plainly: "a copy on the build machine isn't a backup". Losing the upload key isn't fatal, because Play support can reset it, but that takes days.
Building Android apps on an ARM64 server
My CI runner and build machine is an ARM64 server, and Android tooling assumes x86_64 in two places:
- Bubblewrap can download its own JDK and Android SDK, but only x86_64 builds. I installed JDK 17 and the SDK by hand and pointed
~/.bubblewrap/config.jsonat them. Bubblewrap also checks for<sdk>/bin/sdkmanager, which isn't where the command-line tools put it, so that path is a two-line script that runs the real one. - Google ships
aapt2andzipalignfor x86_64 Linux only. They run throughqemu-userwith binfmt, plus one symlink so qemu finds an x86_64 libc:/usr/gnemul/qemu-x86_64points at/usr/x86_64-linux-gnu. After that, the x86_64 binaries just run.
Asset links, and why one key isn't enough
Chrome hides the address bar only if the website vouches for the app. The site does that with /.well-known/assetlinks.json, which lists the SHA-256 fingerprints of the certificates allowed to open it full screen. If the fingerprint doesn't match, the app still works, but it shows a browser bar, so it looks like a web page in a frame.
The catch is that a Play app has two keys:
- the upload key, which I sign the bundle with
- Google's app signing key, which Play re-signs the app with before it reaches anyone's phone
A sideloaded test APK carries the upload key, and the store build carries Google's key. Both fingerprints need to be in assetlinks.json, and you only learn the second one from Play Console after the first upload.
To avoid keeping two lists in sync, the site's assetlinks.json is generated at build time from the same fingerprints array that Bubblewrap edits (bubblewrap fingerprint add …):
prints = [f["value"].upper() for f in twa.get("fingerprints", [])]
for p in prints:
if not re.fullmatch(r"([0-9A-F]{2}:){31}[0-9A-F]{2}", p):
sys.exit(f"✗ twa-manifest.json: bad SHA-256 fingerprint {p!r} (want AA:BB:…, 32 bytes)")
links = [{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {"namespace": "android_app", "package_name": twa["packageId"],
"sha256_cert_fingerprints": prints},
}] if prints else []
With no fingerprints the file is an empty list, which is valid and verifies nothing. The file is a plain static asset, and the Worker never handles it. That's deliberate. When I wrote this, the site answered any unknown path with the app shell, so a missing file came back as index.html with a 200 status. Unknown paths are real 404s now, but the check stays. The Worker's smoke test checks that the URL returns real JSON.
One more trap from the runbook: Android caches the verification result. If the app still shows an address bar after you fix asset links, clear its data.
The back gesture has to end somewhere
In a TWA, the system back gesture walks the web history, and the app closes when there's no history left. That only works if the history is a sensible stack. Gooby's wasn't. The fix's commit message describes the problem:
Every back arrow, Home button and tab pushed a new history entry, so the stack only grew: back from a game's hub reopened the game, and backing out never reached the end where the Play Store app closes.
In a browser tab this is a minor annoyance. In an app it's a bug, because you can't leave. The fix is a custom Dioxus History provider that wraps the browser's history and keeps its own copy of the stack. Every navigation goes through a small planner:
fn plan(stack: &[String], to: &str) -> Move {
let top = stack.len() - 1;
if stack[top] == to {
return Move::Stay;
}
if let Some(i) = stack.iter().rposition(|p| p == to) {
return Move::Back(top - i);
}
if ancestors(&stack[top]).iter().any(|p| p == to) {
return if top > 0 { Move::Back(1) } else { Move::Replace };
}
let up = parent_path(to);
match stack.iter().rposition(|p| Some(p) == up.as_ref()) {
Some(j) if j == top => Move::Push,
Some(j) if j + 1 == top => Move::Replace,
Some(j) => Move::BackThenReplace(top - j - 1),
None => Move::Push,
}
}
The planner works like this:
- A screen that's already on the stack is reached by going back to it (
history.go(-n)), not by pushing it again. - A sibling, such as another tab or the next level, replaces the screen it follows.
- Anything else is pushed.
The stack is saved in sessionStorage, so it survives a reload. A deep link opened in the installed app gets its parent screens filled in behind it, so back still leads somewhere. The end-to-end tests pin this down: after a few moves, page.goBack() from Home must land on about:blank. In other words, one more back leaves the app.
Phones are shorter than you think
I found the next bug while making the Play Store screenshots. Gooby's play screens deliberately can't scroll. Swipe games need every swipe, and a page that moves under your finger loses the game. But a screen that can't scroll has to fit. After an info bar was added to the play screens, Sudoku, Cagey and Kakuro pushed their tool row off the bottom on a 360×740 viewport, which is what the Play Store app gets on a 360×800 phone. They did the same on 16:9 phones and on 320×568. The buttons were simply unreachable.
The tests missed it. In the decision log's words, "Playwright scrolls an overflow: hidden page, a finger can't."
Before the fix, the code used per-game pixel constants for the height of everything that isn't the board, and those constants drifted every time a bar changed. Now a few lines of JavaScript measure it instead. fitPlayScreen adds up the height of every row on a play screen except the board itself, writes the total to a CSS variable, and a ResizeObserver keeps it current. The board then sizes itself from that:
.board-wrap { max-width: min(460px, calc(100dvh - var(--chrome, 0px))); aspect-ratio: 1; }
The rule I settled on is that the board gives up height, never a control. On 320×568 a Sudoku board gets 196 px, and on 360×740 it gets 296 px. Tall phones are unchanged. A touch test now checks every game at five viewport sizes, from 320×568 to 412×860.
The origin is the app
One last thing to understand before shipping: an installed web app belongs to its origin, and its saved games live in that origin's storage. Gooby started on a workers.dev address before moving to gooby.in. The TWA and its asset links are tied to gooby.in only. Anyone who installed the PWA from the old address keeps using it there, because redirecting that origin would cut them off from their saves. (Backup and restore codes do work across hosts.) Pick your domain before you publish the store app.
Play's own rules
Some of the work had nothing to do with code:
- Play wants a public privacy policy and a support page. Gooby has both as ordinary website pages, linked from the listing and from the app's settings.
- New personal developer accounts must run a closed test with 12 or more testers for 14 days before they can publish to production.
- Play rejects a version code it has already seen, so every wrapper update bumps
appVersionCode.
The checklist I'd hand to someone else
- Treat the TWA as a config file and generate the Android project from it.
- Redact signing passwords from build output, and back up the upload key somewhere other than the build machine.
- Generate
assetlinks.jsonfrom the same fingerprint list Bubblewrap uses, and add Play's app signing key after the first upload. - Make sure the back gesture can run out of history, and test that it does.
- Test on short screens with real touch, not a test runner that can scroll what a finger can't.
- Settle the domain first, because the origin owns the players' data.
The result is a store listing for the same site you can open in a browser: no ads, no sign-up, and it works offline.


