fix(android): ship stock MainActivity so the app launches (fixes crash) (1.2.11)

The manifest launches org.skatespots.app.MainActivity; when that class was
missing/wrong the app crashed on startup. Add a STOCK MainActivity (extends
BridgeActivity, no WebViewClient override) plus an idempotent injector that
guarantees it's always present after cap add / rm -rf android. This is the safe
default — the earlier custom version broke startup. Delete fix (setPackageName)
remains intact. Bump to 1.2.11.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-09-04 22:20:18 +07:00
parent 88685262ce
commit 955a823b02
3 changed files with 73 additions and 4 deletions

View file

@ -0,0 +1,20 @@
package org.skatespots.app;
import com.getcapacitor.BridgeActivity;
/**
* Default Capacitor launcher activity.
*
* This is the STOCK Capacitor MainActivity — it does NOT override the
* WebViewClient or anything else. An earlier custom version overrode the
* WebViewClient and wiped out the client Capacitor needs to load the web layer,
* causing a black-screen crash on launch. This minimal version simply exists so
* the AndroidManifest has a valid launcher class to point at, and lets Capacitor
* boot normally.
*
* Injected into the generated android/ project at build time by
* scripts/inject-main-activity.mjs so the correct class is always present even
* after `rm -rf android` / `cap add`.
*/
public class MainActivity extends BridgeActivity {
}

View file

@ -1,7 +1,7 @@
{
"name": "skate-spots",
"private": true,
"version": "1.2.10",
"version": "1.2.11",
"type": "module",
"homepage": "https://skate-spots.com",
"scripts": {
@ -9,11 +9,11 @@
"build": "npm i --silent && vite build -l error && cp dist/index.html dist/404.html && echo 'Project built successfully!'",
"test": "npm i --silent && tsc --noEmit && eslint && vitest run --reporter=dot --silent && vite build -l error && cp dist/index.html dist/404.html && echo 'All tests passed!'",
"deploy": "npm i --silent && npm run build && npx -y nostr-deploy-cli deploy --skip-setup",
"android:init": "npm run android:build:apk && npx cap add android && npx cap sync android && node scripts/inject-amber-queries.mjs",
"android:sync": "npm run android:build:apk && npx cap sync android && node scripts/sync-android-version.mjs && node scripts/inject-amber-queries.mjs",
"android:init": "npm run android:build:apk && npx cap add android && npx cap sync android && node scripts/inject-amber-queries.mjs && node scripts/inject-main-activity.mjs",
"android:sync": "npm run android:build:apk && npx cap sync android && node scripts/sync-android-version.mjs && node scripts/inject-amber-queries.mjs && node scripts/inject-main-activity.mjs",
"android:open": "npx cap open android",
"android:version": "node scripts/sync-android-version.mjs",
"android:build": "npm run android:build:apk && npx cap sync android && node scripts/sync-android-version.mjs && node scripts/inject-amber-queries.mjs && cd android && ./gradlew assembleRelease",
"android:build": "npm run android:build:apk && npx cap sync android && node scripts/sync-android-version.mjs && node scripts/inject-amber-queries.mjs && node scripts/inject-main-activity.mjs && cd android && ./gradlew assembleRelease",
"android:build:apk": "CAPACITOR_BUILD=1 vite build && sed -i 's|<script type=\"module\" src=\"/shakespeare_tailwind[^\"]*\\.js\"></script>||g' dist/index.html && sed -i 's|<style type=\"text/tailwindcss\">|<style>|g' dist/index.html && cp dist/index.html dist/404.html"
},
"dependencies": {

View file

@ -0,0 +1,49 @@
#!/usr/bin/env node
/**
* Ensure the correct (stock) MainActivity.java exists in the generated Android
* project.
*
* The AndroidManifest launches org.skatespots.app.MainActivity. If that class is
* missing or wrong, the app crashes on launch (black screen). We keep the stock
* source of truth in android-templates/MainActivity.java and copy it in on every
* build so the launcher class is ALWAYS present and correct — even after
* `rm -rf android` or `cap add` regenerate things.
*
* This version does NOT override the WebViewClient (a previous custom version
* did and broke startup). Idempotent. Exits quietly if android/ isn't generated.
*/
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
const targetDir = join(root, 'android', 'app', 'src', 'main', 'java', 'org', 'skatespots', 'app');
const target = join(targetDir, 'MainActivity.java');
const template = join(root, 'android-templates', 'MainActivity.java');
// If the android/ project hasn't been generated yet, do nothing.
if (!existsSync(join(root, 'android', 'app'))) {
console.log('[inject-main-activity] android/ not generated yet — skipping.');
process.exit(0);
}
if (!existsSync(template)) {
console.error('[inject-main-activity] template android-templates/MainActivity.java missing — aborting.');
process.exit(1);
}
if (!existsSync(targetDir)) {
mkdirSync(targetDir, { recursive: true });
}
const desired = readFileSync(template, 'utf8');
const current = existsSync(target) ? readFileSync(target, 'utf8') : null;
if (current === desired) {
console.log('[inject-main-activity] MainActivity.java already correct.');
process.exit(0);
}
copyFileSync(template, target);
console.log('[inject-main-activity] ✓ Ensured stock MainActivity.java is present (fixes black-screen crash).');