Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ export interface CapacitorConfig {
releaseType?: 'AAB' | 'APK';

/**
* Program to sign your build with
* Program to sign your build with. Defaults to `apksigner` for APKs and
* `jarsigner` for Android App Bundles. `apksigner` must be on your PATH
* when used.
*
* @since 5.1.0
* @default "jarsigner"
*/
signingType?: 'apksigner' | 'jarsigner';
};
Expand Down
8 changes: 4 additions & 4 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ export function runProgram(config: Config): void {
]),
)
.addOption(
new Option('--signing-type <signingtype>', 'Program used to sign apps (default: jarsigner)').choices([
'apksigner',
'jarsigner',
]),
new Option(
'--signing-type <signingtype>',
'Program used to sign apps (default: apksigner for APK, jarsigner for AAB)',
).choices(['apksigner', 'jarsigner']),
)
.addOption(
new Option('--xcode-team-id <xcodeTeamID>', 'The Developer team to use for building and exporting the archive'),
Expand Down
8 changes: 6 additions & 2 deletions cli/src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ export async function buildCommand(
);
}

const androidReleaseType = buildOptions.androidreleasetype || config.android.buildOptions.releaseType || 'AAB';
const buildCommandOptions: BuildCommandOptions = {
scheme: buildOptions.scheme || config.ios.scheme,
flavor: buildOptions.flavor || config.android.flavor,
keystorepath: buildOptions.keystorepath || config.android.buildOptions.keystorePath,
keystorepass: buildOptions.keystorepass || config.android.buildOptions.keystorePassword,
keystorealias: buildOptions.keystorealias || config.android.buildOptions.keystoreAlias,
keystorealiaspass: buildOptions.keystorealiaspass || config.android.buildOptions.keystoreAliasPassword,
androidreleasetype: buildOptions.androidreleasetype || config.android.buildOptions.releaseType || 'AAB',
signingtype: buildOptions.signingtype || config.android.buildOptions.signingType || 'jarsigner',
androidreleasetype: androidReleaseType,
signingtype:
buildOptions.signingtype ||
config.android.buildOptions.signingType ||
(androidReleaseType === 'APK' ? 'apksigner' : 'jarsigner'),
configuration: buildOptions.configuration || 'Release',
xcodeTeamId: buildOptions.xcodeTeamId || config.ios.buildOptions.teamId,
xcodeExportMethod:
Expand Down
73 changes: 73 additions & 0 deletions cli/test/build.signing.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { join } from 'path';

import type { Config } from '../src/definitions';
import { buildCommand } from '../src/tasks/build';
import type { BuildCommandOptions } from '../src/tasks/build';
import { runCommand } from '../src/util/subprocess';

jest.mock('../src/common', () => ({
selectPlatforms: jest.fn().mockResolvedValue(['android']),
runTask: jest.fn((_title, task) => task()),
}));
jest.mock('../src/log', () => ({ logSuccess: jest.fn() }));
jest.mock('../src/util/subprocess', () => ({ runCommand: jest.fn().mockResolvedValue('') }));

describe('Android build signing defaults', () => {
beforeEach(() => jest.clearAllMocks());

it.each([
['default bundle', {}, {}, 'AAB', 'jarsigner'],
['CLI APK', { androidreleasetype: 'APK' }, {}, 'APK', 'apksigner'],
['configured APK', {}, { releaseType: 'APK' }, 'APK', 'apksigner'],
['CLI AAB overrides configured APK', { androidreleasetype: 'AAB' }, { releaseType: 'APK' }, 'AAB', 'jarsigner'],
['CLI APK overrides configured AAB', { androidreleasetype: 'APK' }, { releaseType: 'AAB' }, 'APK', 'apksigner'],
['explicit CLI jarsigner', { androidreleasetype: 'APK', signingtype: 'jarsigner' }, {}, 'APK', 'jarsigner'],
['configured jarsigner', {}, { releaseType: 'APK', signingType: 'jarsigner' }, 'APK', 'jarsigner'],
[
'CLI signer overrides configured signer',
{ signingtype: 'apksigner' },
{ releaseType: 'APK', signingType: 'jarsigner' },
'APK',
'apksigner',
],
] as const)('%s', async (_name, cliOptions, configuredOptions, releaseType, signer) => {
const config = {
android: {
name: 'android',
platformDirAbs: '/test/android',
appDirAbs: '/test/android/app',
buildOptions: {
keystorePath: 'test.jks',
keystorePassword: 'test-password',
keystoreAlias: 'test',
keystoreAliasPassword: 'test-password',
...configuredOptions,
},
},
ios: { name: 'ios', buildOptions: {} },
} as Config;

await buildCommand(config, 'android', { configuration: 'Release', ...cliOptions } as BuildCommandOptions);

expect(runCommand).toHaveBeenCalledTimes(2);
expect(runCommand).toHaveBeenNthCalledWith(
1,
'./gradlew',
[releaseType === 'APK' ? 'assembleRelease' : ':app:bundleRelease'],
{ cwd: '/test/android' },
);
expect(runCommand).toHaveBeenNthCalledWith(
2,
signer,
expect.arrayContaining([
join(
'/test/android/app/build/outputs',
releaseType === 'APK' ? 'apk' : 'bundle',
'release',
`app-release-signed.${releaseType.toLowerCase()}`,
),
]),
{ cwd: '/test/android' },
);
});
});