Spaces:
Sleeping
Sleeping
| // Script for building a standalone APK that doesn't need a dev server | |
| import { execSync } from 'child_process'; | |
| import * as fs from 'fs'; | |
| import * as path from 'path'; | |
| import { fileURLToPath } from 'url'; | |
| // Get the directory name in ES modules | |
| const __filename = fileURLToPath(import.meta.url); | |
| const __dirname = path.dirname(__filename); | |
| try { | |
| // Run npm build | |
| console.log('ποΈ Building the project...'); | |
| execSync('npm run build', { stdio: 'inherit' }); | |
| // Run cap sync | |
| console.log('π± Synchronizing Capacitor project...'); | |
| execSync('npx cap sync android', { stdio: 'inherit' }); | |
| // Copy standalone config to the main config location AFTER sync | |
| console.log('π Applying standalone configuration...'); | |
| const standaloneConfig = fs.readFileSync(path.join(__dirname, 'capacitor.config.standalone.json'), 'utf8'); | |
| fs.writeFileSync(path.join(__dirname, 'android/app/src/main/assets/capacitor.config.json'), standaloneConfig); | |
| console.log('β Standalone config applied'); | |
| // Build the APK | |
| console.log('π¦ Building both debug and release APKs...'); | |
| execSync('cd android && .\\gradlew.bat assembleDebug assembleRelease', { stdio: 'inherit' }); | |
| console.log(''); | |
| console.log('β Standalone APKs have been built successfully!'); | |
| console.log(''); | |
| console.log('π± Debug APK (for testing): android/app/build/outputs/apk/debug/app-debug.apk'); | |
| console.log('π± Release APK (for distribution): android/app/build/outputs/apk/release/app-release.apk'); | |
| console.log(''); | |
| console.log('These APKs contain all your web assets and do not need a development server to run.'); | |
| console.log('You can directly install them on any Android device.'); | |
| } catch (error) { | |
| console.error('β Error:', error.message); | |
| } |