Skip to content

fix(android): read .env.app in capacitor.config.ts so allowNavigation actually ships - #219

Merged
hatafatif merged 1 commit into
developfrom
bd-2676-build
Aug 13, 2026
Merged

fix(android): read .env.app in capacitor.config.ts so allowNavigation actually ships#219
hatafatif merged 1 commit into
developfrom
bd-2676-build

Conversation

@hatafatif

Copy link
Copy Markdown
Collaborator

Caught by inspecting the built artifact rather than trusting the build's exit code.

The failure

The v1212 AAB built green — every pre-upload check in build-niete-aab.sh passed — and shipped with:

"android": {},
"server": { "androidScheme": "https", "hostname": "localhost" }

No allowNavigation. The entire native half of bd-2676 was in the source and absent from the artifact that would have gone to Play. Uploading it would have burned a versionCode and fixed nothing.

Cause

capacitor.config.ts is plain Node. Vite loads .env.app; this file does not. The release script runs cap sync in a subshell, so VITE_API_BASE_URL was undefined at sync time, allowedNavigationHosts() correctly returned [], and the spread omitted the key — with a SUCCESSFUL build either way.

Same class as the documented ".env.app gap" that once produced an APK with no server.url. Both are invisible unless you open the generated config.

Fix

One resolver, configuredApiBaseUrl(): process.env first (so CI secrets still win), then a parse of .env.app. Both the OTA url and the navigation allowlist derive from that single value, so the host serving the code cannot drift from the host the app may navigate to.

Verified in the packaged v1213 artifact:

"server": { ..., "allowNavigation": ["portal.niete.edu.pk"] }

Also found — a live contradiction, not fixed here

resolveOtaUrl() returns url.origin (bare), but build-niete-aab.sh rejects a bare origin and demands a /portal/... path (bd-2562). So no NIETE_OTA=1 build can currently pass its own guard. I built v1213 with NIETE_OTA=0 (bundled assets) to sidestep it. That's a pre-existing repo bug worth its own bead — the skill documents the /portal/login fix as shipped, but the code returns the bare origin.

Tests

Pin the .env.app fallback, the env-wins-over-file ordering, and the single-source derivation — so this cannot silently regress into another green-but-empty artifact.

Refs: bd-2676

🤖 Generated with Claude Code

… ships

Caught by inspecting the built artifact rather than the build's exit code.

The v1212 AAB built GREEN — every pre-upload check passed — and shipped with
`"android": {}` and NO allowNavigation at all. The fix was in the source and
absent from the thing that would have gone to Play.

Cause: capacitor.config.ts is plain Node. Vite loads `.env.app`; this file does
not. The release script runs `cap sync` in a subshell, so VITE_API_BASE_URL was
undefined at sync time and every value derived from it silently vanished from
the generated native config — with a SUCCESSFUL build either way. Same class as
the documented ".env.app gap" that once produced an APK with no server.url.

Now resolved once, via configuredApiBaseUrl(): process.env first (so CI secrets
still win), then a parse of .env.app. Both the OTA url and the navigation
allowlist derive from that single value, so the host serving the code cannot
drift from the host the app is allowed to navigate to.

Verified in the PACKAGED v1213 artifact:
  "server": { ..., "allowNavigation": ["portal.niete.edu.pk"] }

Tests pin the fallback, the env-wins-over-file order, and the single-source
derivation.

Refs: bd-2676
@hatafatif
hatafatif merged commit f56e3a9 into develop Aug 13, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant