diff --git a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart index a8873a65..8821de3f 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart @@ -41,6 +41,16 @@ class ReleaseAndroidCommand extends ShorebirdCommand 'flavor', help: 'The product flavor to use when building the app.', ) + ..addOption( + 'artifact', + help: 'They type of artifact to generate.', + allowed: ['aab', 'apk'], + defaultsTo: 'aab', + allowedHelp: { + 'aab': 'Android App Bundle', + 'apk': 'Android Package Kit', + }, + ) ..addFlag( 'force', abbr: 'f', @@ -74,9 +84,11 @@ make smaller updates to your app. const platformName = 'android'; final flavor = results['flavor'] as String?; final target = results['target'] as String?; + final generateApk = results['artifact'] as String == 'apk'; final buildProgress = logger.progress('Building release'); try { await buildAppBundle(flavor: flavor, target: target); + if (generateApk) await buildApk(flavor: flavor, target: target); buildProgress.complete(); } on ProcessException catch (error) { buildProgress.fail('Failed to build: ${error.message}'); @@ -92,6 +104,10 @@ make smaller updates to your app. final bundlePath = flavor != null ? p.join(bundleDirPath, '${flavor}Release', 'app-$flavor-release.aab') : p.join(bundleDirPath, 'release', 'app-release.aab'); + final apkDirPath = p.join('build', 'app', 'outputs', 'apk'); + final apkPath = flavor != null + ? p.join(apkDirPath, flavor, 'release', 'app-$flavor-release.apk') + : p.join(apkDirPath, 'release', 'app-release.apk'); final String releaseVersion; final detectReleaseVersionProgress = logger.progress( @@ -176,8 +192,8 @@ ${summary.join('\n')} ..success('\n✅ Published Release!') ..info(''' -Your next step is to upload the app bundle to the Play Store. -${lightCyan.wrap(bundlePath)} +Your next step is to upload the ${generateApk ? 'apk' : 'app bundle'} to the Play Store. +${lightCyan.wrap(generateApk ? apkPath : bundlePath)} See the following link for more information: ${link(uri: Uri.parse('https://support.google.com/googleplay/android-developer/answer/9859152?hl=en'))} diff --git a/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart index 19e19dce..1e0f3d62 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart @@ -172,6 +172,7 @@ flutter: when(() => argResults.rest).thenReturn([]); when(() => argResults['arch']).thenReturn(arch); when(() => argResults['platform']).thenReturn(platformName); + when(() => argResults['artifact']).thenReturn('aab'); when(() => auth.isAuthenticated).thenReturn(true); when(() => auth.client).thenReturn(httpClient); when(() => cache.updateAll()).thenAnswer((_) async => {}); @@ -423,6 +424,27 @@ flutter: expect(exitCode, ExitCode.success.code); }); + test('succeeds when release is successful (with apk)', () async { + when(() => argResults['artifact']).thenReturn('apk'); + final tempDir = setUpTempDir(); + + final exitCode = await IOOverrides.runZoned( + () => runWithOverrides(command.run), + getCurrentDirectory: () => tempDir, + ); + + verify(() => logger.success('\n✅ Published Release!')).called(1); + verify( + () => codePushClientWrapper.createAndroidReleaseArtifacts( + releaseId: release.id, + platform: platformName, + aabPath: any(named: 'aabPath'), + architectures: any(named: 'architectures'), + ), + ).called(1); + expect(exitCode, ExitCode.success.code); + }); + test( 'succeeds when release is successful ' 'with flavors and target', () async {