2025-06-18 18:50:46 +02:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . runAndroid = void 0 ;
const tslib _1 = require ( "tslib" ) ;
const debug _1 = tslib _1 . _ _importDefault ( require ( "debug" ) ) ;
const path _1 = require ( "path" ) ;
const colors _1 = tslib _1 . _ _importDefault ( require ( "../colors" ) ) ;
const common _1 = require ( "../common" ) ;
const native _run _1 = require ( "../util/native-run" ) ;
const subprocess _1 = require ( "../util/subprocess" ) ;
const debug = ( 0 , debug _1 . default ) ( 'capacitor:android:run' ) ;
2025-07-06 20:20:48 +02:00
async function runAndroid ( config , { target : selectedTarget , flavor : selectedFlavor , forwardPorts : selectedPorts } ) {
2025-06-18 18:50:46 +02:00
var _a ;
const target = await ( 0 , common _1 . promptForPlatformTarget ) ( await ( 0 , native _run _1 . getPlatformTargets ) ( 'android' ) , selectedTarget ) ;
const runFlavor = selectedFlavor || ( ( _a = config . android ) === null || _a === void 0 ? void 0 : _a . flavor ) || '' ;
const arg = ` assemble ${ runFlavor } Debug ` ;
const gradleArgs = [ arg ] ;
debug ( 'Invoking ./gradlew with args: %O' , gradleArgs ) ;
try {
await ( 0 , common _1 . runTask ) ( 'Running Gradle build' , async ( ) => ( 0 , subprocess _1 . runCommand ) ( './gradlew' , gradleArgs , {
cwd : config . android . platformDirAbs ,
} ) ) ;
}
catch ( e ) {
if ( e . includes ( 'EACCES' ) ) {
throw ` gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${ colors _1 . default . strong ( ` chmod +x ./ ${ config . android . platformDir } /gradlew ` ) } and try again. ` ;
}
else {
throw e ;
}
}
const pathToApk = ` ${ config . android . platformDirAbs } / ${ config . android . appDir } /build/outputs/apk ${ runFlavor !== '' ? '/' + runFlavor : '' } /debug ` ;
const apkName = ( 0 , common _1 . parseApkNameFromFlavor ) ( runFlavor ) ;
const apkPath = ( 0 , path _1 . resolve ) ( pathToApk , apkName ) ;
const nativeRunArgs = [ 'android' , '--app' , apkPath , '--target' , target . id ] ;
if ( selectedPorts ) {
nativeRunArgs . push ( '--forward' , ` ${ selectedPorts } ` ) ;
}
debug ( 'Invoking native-run with args: %O' , nativeRunArgs ) ;
await ( 0 , common _1 . runTask ) ( ` Deploying ${ colors _1 . default . strong ( apkName ) } to ${ colors _1 . default . input ( target . id ) } ` , async ( ) => ( 0 , native _run _1 . runNativeRun ) ( nativeRunArgs ) ) ;
}
exports . runAndroid = runAndroid ;