[tool][android] Allow --target-platform work properly with --debug mode (#154476)

This PR addresses an issue where the `--target-platform` flag was not being respected when building APKs in debug mode. Previously, debug builds would always include `x86` and `x64` architectures, regardless of the specified target platform. This change ensures that the `--target-platform` flag is honored across all build modes, including debug.

To achieve this, `BuildApkCommand` has been slightly changed to become responsible for list of archs that should be built in the current run,rather than just parsing arguments. Previously, this responsibility was distributed to gradle, which could be frustrating (in my opinion)

Fixes #153359
This commit is contained in:
Mikhail Novoseltsev
2024-10-01 20:24:53 +05:00
committed by GitHub
parent 6bba08cbcc
commit 0975e612c0
5 changed files with 190 additions and 48 deletions

View File

@@ -48,8 +48,9 @@ void main() {
testUsingContext('indicate the default target platforms', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
await runBuildApkCommand(projectPath);
// Without buildMode flag.
await runBuildApkCommand(projectPath);
expect(
fakeAnalytics.sentEvents,
contains(
@@ -62,6 +63,157 @@ void main() {
),
),
);
await runBuildApkCommand(projectPath, arguments: <String>['--debug']);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm,android-arm64,android-x86,android-x64',
buildApkBuildMode: 'debug',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(projectPath, arguments: <String>['--jit-release']);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm,android-arm64,android-x86,android-x64',
buildApkBuildMode: 'jit_release',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(projectPath, arguments: <String>['--profile']);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm,android-arm64,android-x64',
buildApkBuildMode: 'profile',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(projectPath, arguments: <String>['--release']);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm,android-arm64,android-x64',
buildApkBuildMode: 'release',
buildApkSplitPerAbi: false,
),
),
);
}, overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(),
Analytics: () => fakeAnalytics,
});
testUsingContext('Each build mode respects --target-platform', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
// Without buildMode flag.
await runBuildApkCommand(
projectPath,
arguments: <String>['--target-platform=android-arm'],
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm',
buildApkBuildMode: 'release',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(
projectPath,
arguments: <String>['--debug', '--target-platform=android-arm'],
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm',
buildApkBuildMode: 'debug',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(
projectPath,
arguments: <String>['--release', '--target-platform=android-arm'],
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm',
buildApkBuildMode: 'release',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(
projectPath,
arguments: <String>['--profile', '--target-platform=android-arm'],
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm',
buildApkBuildMode: 'profile',
buildApkSplitPerAbi: false,
),
),
);
await runBuildApkCommand(
projectPath,
arguments: <String>['--jit-release', '--target-platform=android-arm'],
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.commandUsageValues(
workflow: 'apk',
commandHasTerminal: false,
buildApkTargetPlatform: 'android-arm',
buildApkBuildMode: 'jit_release',
buildApkSplitPerAbi: false,
),
),
);
}, overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(),
Analytics: () => fakeAnalytics,