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>
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
#!/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).');
|