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);
}