diff --git a/mobile/package.json b/mobile/package.json index 5276a000f..56f8830c5 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -9,7 +9,8 @@ "web:sync": "node scripts/sync-web.mjs", "android:init": "pnpm install && pnpm exec cap init DeskClaw dev.deskclaw.app --web-dir=www --npm-client=pnpm", "android:add": "pnpm exec cap add android", - "android:sync": "pnpm exec cap sync android", + "android:patch": "node scripts/patch-android.mjs", + "android:sync": "pnpm exec cap sync android && pnpm run android:patch", "android:apk:debug": "cd android && ./gradlew assembleDebug", "android:apk:release": "cd android && ./gradlew assembleRelease" }, @@ -21,4 +22,3 @@ "@capacitor/cli": "^7.4.3" } } - diff --git a/mobile/scripts/patch-android.mjs b/mobile/scripts/patch-android.mjs new file mode 100644 index 000000000..3f1bb3c49 --- /dev/null +++ b/mobile/scripts/patch-android.mjs @@ -0,0 +1,25 @@ +import { readFile, writeFile } from 'node:fs/promises' +import { resolve } from 'node:path' +import { fileURLToPath } from 'node:url' + +async function main() { + const scriptDir = fileURLToPath(new URL('.', import.meta.url)) + const mobileRoot = resolve(scriptDir, '..') + const appGradle = resolve(mobileRoot, 'android', 'app', 'build.gradle') + + let text = await readFile(appGradle, 'utf8') + const before = "implementation project(':capacitor-android')" + const after = 'implementation "com.capacitorjs:core:7.6.2"' + + if (text.includes(after)) return + if (!text.includes(before)) return + + text = text.replace(before, after) + await writeFile(appGradle, text, 'utf8') +} + +main().catch((err) => { + console.error(err) + process.exit(1) +}) +