Spaces:
Sleeping
Sleeping
File size: 1,806 Bytes
d97b8f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // 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);
} |