pmtool / build-standalone.js
devarshia5's picture
Upload 487 files
d97b8f9 verified
Raw
History Blame Contribute Delete
1.81 kB
// 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);
}