2025-06-18 18:50:46 +02:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . buildAndroid = void 0 ;
const tslib _1 = require ( "tslib" ) ;
const path _1 = require ( "path" ) ;
const colors _1 = tslib _1 . _ _importDefault ( require ( "../colors" ) ) ;
const common _1 = require ( "../common" ) ;
const log _1 = require ( "../log" ) ;
const subprocess _1 = require ( "../util/subprocess" ) ;
async function buildAndroid ( config , buildOptions ) {
var _a , _b ;
const releaseType = ( _a = buildOptions . androidreleasetype ) !== null && _a !== void 0 ? _a : 'AAB' ;
const releaseTypeIsAAB = releaseType === 'AAB' ;
const flavor = ( _b = buildOptions . flavor ) !== null && _b !== void 0 ? _b : '' ;
2025-07-06 20:20:48 +02:00
const arg = releaseTypeIsAAB ? ` :app:bundle ${ flavor } Release ` : ` assemble ${ flavor } Release ` ;
2025-06-18 18:50:46 +02:00
const gradleArgs = [ arg ] ;
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 releaseDir = releaseTypeIsAAB
? flavor !== ''
? ` ${ flavor } Release `
: 'release'
: flavor !== ''
? ( 0 , path _1 . join ) ( flavor , 'release' )
: 'release' ;
const releasePath = ( 0 , path _1 . join ) ( config . android . appDirAbs , 'build' , 'outputs' , releaseTypeIsAAB ? 'bundle' : 'apk' , releaseDir ) ;
const unsignedReleaseName = ` app ${ flavor !== '' ? ` - ${ flavor } ` : '' } -release ${ releaseTypeIsAAB ? '' : '-unsigned' } . ${ releaseType . toLowerCase ( ) } ` ;
const signedReleaseName = unsignedReleaseName . replace ( ` -release ${ releaseTypeIsAAB ? '' : '-unsigned' } . ${ releaseType . toLowerCase ( ) } ` , ` -release-signed. ${ releaseType . toLowerCase ( ) } ` ) ;
if ( buildOptions . signingtype == 'jarsigner' ) {
await signWithJarSigner ( config , buildOptions , releasePath , signedReleaseName , unsignedReleaseName ) ;
}
else {
await signWithApkSigner ( config , buildOptions , releasePath , signedReleaseName , unsignedReleaseName ) ;
}
( 0 , log _1 . logSuccess ) ( ` Successfully generated ${ signedReleaseName } at: ${ releasePath } ` ) ;
}
exports . buildAndroid = buildAndroid ;
async function signWithApkSigner ( config , buildOptions , releasePath , signedReleaseName , unsignedReleaseName ) {
if ( ! buildOptions . keystorepath || ! buildOptions . keystorepass ) {
throw 'Missing options. Please supply all options for android signing. (Keystore Path, Keystore Password)' ;
}
const signingArgs = [
'sign' ,
'--ks' ,
buildOptions . keystorepath ,
'--ks-pass' ,
` pass: ${ buildOptions . keystorepass } ` ,
'--in' ,
` ${ ( 0 , path _1 . join ) ( releasePath , unsignedReleaseName ) } ` ,
'--out' ,
` ${ ( 0 , path _1 . join ) ( releasePath , signedReleaseName ) } ` ,
] ;
if ( buildOptions . keystorealias ) {
signingArgs . push ( '--ks-key-alias' , buildOptions . keystorealias ) ;
}
if ( buildOptions . keystorealiaspass ) {
signingArgs . push ( '--key-pass' , ` pass: ${ buildOptions . keystorealiaspass } ` ) ;
}
await ( 0 , common _1 . runTask ) ( 'Signing Release' , async ( ) => {
await ( 0 , subprocess _1 . runCommand ) ( 'apksigner' , signingArgs , {
cwd : config . android . platformDirAbs ,
} ) ;
} ) ;
}
async function signWithJarSigner ( config , buildOptions , releasePath , signedReleaseName , unsignedReleaseName ) {
if ( ! buildOptions . keystorepath ||
! buildOptions . keystorealias ||
! buildOptions . keystorealiaspass ||
! buildOptions . keystorepass ) {
throw 'Missing options. Please supply all options for android signing. (Keystore Path, Keystore Password, Keystore Key Alias, Keystore Key Password)' ;
}
const signingArgs = [
'-sigalg' ,
'SHA1withRSA' ,
'-digestalg' ,
'SHA1' ,
'-keystore' ,
buildOptions . keystorepath ,
'-keypass' ,
buildOptions . keystorealiaspass ,
'-storepass' ,
buildOptions . keystorepass ,
` -signedjar ` ,
` ${ ( 0 , path _1 . join ) ( releasePath , signedReleaseName ) } ` ,
` ${ ( 0 , path _1 . join ) ( releasePath , unsignedReleaseName ) } ` ,
buildOptions . keystorealias ,
] ;
await ( 0 , common _1 . runTask ) ( 'Signing Release' , async ( ) => {
await ( 0 , subprocess _1 . runCommand ) ( 'jarsigner' , signingArgs , {
cwd : config . android . platformDirAbs ,
} ) ;
} ) ;
}