Skip to content

Commit e832053

Browse files
committed
Address review feedback on AndroidBuildInfo and AndroidGradleConfig
- Remove `gradleDaemon` and `skipBuildDependencyValidation` forwarding getters from `AndroidBuildInfo` and read `buildInfo.androidGradleConfig` directly in `gradle.dart`. - Move `-Psplit-per-abi=true` into `AndroidBuildInfo.toGradleConfig()` and clarify `targetArchs` (`-Ptarget-platform`) in its Dartdoc. - Add `DummyAllBuildOptionsFlutterCommand` CLI parsing test for `AndroidGradleConfig` options in `flutter_command_test.dart`. - Clean up test description and comment in `android_gradle_builder_test.dart`.
1 parent 1a389f4 commit e832053

5 files changed

Lines changed: 42 additions & 29 deletions

File tree

‎packages/flutter_tools/lib/src/android/gradle.dart‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
457457
FlutterProject project,
458458
AndroidBuildInfo androidBuildInfo,
459459
) async {
460-
if (!androidBuildInfo.skipBuildDependencyValidation) {
460+
if (!androidBuildInfo.buildInfo.androidGradleConfig.skipBuildDependencyValidation) {
461461
final Version? javaVersionObj = _java?.version;
462462
final String? javaVersion = javaVersionObj != null
463463
? '${javaVersionObj.major}.${javaVersionObj.minor}.${javaVersionObj.patch}'
@@ -570,10 +570,10 @@ To fix this, you can either:
570570
} else {
571571
options.add('-q');
572572
}
573-
if (!androidBuildInfo.gradleDaemon) {
573+
if (!buildInfo.androidGradleConfig.gradleDaemon) {
574574
options.add('--no-daemon');
575575
}
576-
if (androidBuildInfo.skipBuildDependencyValidation) {
576+
if (buildInfo.androidGradleConfig.skipBuildDependencyValidation) {
577577
options.add('-PskipDependencyChecks=true');
578578
}
579579
final LocalEngineInfo? localEngineInfo = _artifacts.localEngineInfo;
@@ -648,9 +648,6 @@ To fix this, you can either:
648648
if (buildInfo.fileSystemScheme != null) {
649649
options.add('-Pfilesystem-scheme=${buildInfo.fileSystemScheme}');
650650
}
651-
if (androidBuildInfo.splitPerAbi) {
652-
options.add('-Psplit-per-abi=true');
653-
}
654651

655652
options.addAll(_getAndroidNdkProvisioningProperties());
656653
late Stopwatch sw;
@@ -900,7 +897,7 @@ To fix this, you can either:
900897
} else {
901898
command.add('-q');
902899
}
903-
if (!androidBuildInfo.gradleDaemon) {
900+
if (!buildInfo.androidGradleConfig.gradleDaemon) {
904901
command.add('--no-daemon');
905902
}
906903

‎packages/flutter_tools/lib/src/build_info.dart‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,16 +476,11 @@ class AndroidBuildInfo {
476476
/// from source (i.e., not using a prebuilt application binary).
477477
final List<String>? releaseManifestEngineShellArgs;
478478

479-
/// Whether to enable the Gradle daemon when performing an Android build.
480-
bool get gradleDaemon => buildInfo.androidGradleConfig.gradleDaemon;
481-
482-
/// Whether to skip checking of individual versions of our Android build time
483-
/// dependencies.
484-
bool get skipBuildDependencyValidation =>
485-
buildInfo.androidGradleConfig.skipBuildDependencyValidation;
486-
487-
/// Convert this config to a series of project level arguments to be passed
488-
/// on the command line to gradle.
479+
/// Converts [buildInfo], [BuildInfo.androidGradleConfig], and [splitPerAbi]
480+
/// into project-level arguments to be passed on the command line to Gradle.
481+
///
482+
/// Note that [targetArchs] (`-Ptarget-platform`) is resolved by the Gradle
483+
/// builder so `--local-engine` can override it from the local engine path.
489484
List<String> toGradleConfig() {
490485
final AndroidGradleConfig gradleConfig = buildInfo.androidGradleConfig;
491486
// PACKAGE_CONFIG not currently supported.
@@ -513,6 +508,7 @@ class AndroidBuildInfo {
513508
for (final String projectArg in gradleConfig.projectArgs) '-P$projectArg',
514509
if (gradleConfig.projectCacheDir != null)
515510
'--project-cache-dir=${gradleConfig.projectCacheDir}',
511+
if (splitPerAbi) '-Psplit-per-abi=true',
516512
];
517513
}
518514
}

‎packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,7 @@ Gradle Crashed
33543354
);
33553355

33563356
testUsingContext(
3357-
'skips Java and Gradle compatibility check when androidSkipBuildDependencyValidation is true',
3357+
'skips Java and Gradle compatibility check when skipBuildDependencyValidation is true',
33583358
() async {
33593359
final AndroidGradleBuilder builder = createBuilder(
33603360
java: FakeJava(version: const Version.withText(21, 0, 0, '21.0.0')),
@@ -3426,9 +3426,7 @@ Gradle Crashed
34263426
'dev',
34273427
treeShakeIcons: false,
34283428
packageConfigPath: '.dart_tool/package_config.json',
3429-
androidGradleConfig: AndroidGradleConfig(
3430-
skipBuildDependencyValidation: true,
3431-
), // Skip validation
3429+
androidGradleConfig: AndroidGradleConfig(skipBuildDependencyValidation: true),
34323430
),
34333431
),
34343432
target: 'lib/main.dart',

‎packages/flutter_tools/test/general.shard/build_info_test.dart‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,6 @@ void main() {
324324
expect(BuildInfo.debug.androidGradleConfig.enableHcpp, isNull);
325325
expect(BuildInfo.debug.androidGradleConfig.explicitEnableHcpp, isNull);
326326

327-
const defaultAndroidBuildInfo = AndroidBuildInfo(BuildInfo.debug);
328-
expect(defaultAndroidBuildInfo.gradleDaemon, isTrue);
329-
expect(defaultAndroidBuildInfo.skipBuildDependencyValidation, isFalse);
330-
331327
const customConfig = AndroidGradleConfig(
332328
projectArgs: <String>['a=1', 'b=2'],
333329
projectCacheDir: '/custom/cache',
@@ -343,10 +339,11 @@ void main() {
343339
packageConfigPath: 'foo/.dart_tool/package_config.json',
344340
androidGradleConfig: customConfig,
345341
);
346-
const customAndroidBuildInfo = AndroidBuildInfo(customBuildInfo);
347342

348-
expect(customAndroidBuildInfo.gradleDaemon, isFalse);
349-
expect(customAndroidBuildInfo.skipBuildDependencyValidation, isTrue);
343+
expect(customBuildInfo.androidGradleConfig.projectArgs, <String>['a=1', 'b=2']);
344+
expect(customBuildInfo.androidGradleConfig.projectCacheDir, '/custom/cache');
345+
expect(customBuildInfo.androidGradleConfig.gradleDaemon, isFalse);
346+
expect(customBuildInfo.androidGradleConfig.skipBuildDependencyValidation, isTrue);
350347
expect(customBuildInfo.copyWith().androidGradleConfig, same(customConfig));
351348
});
352349

@@ -370,7 +367,7 @@ void main() {
370367
projectCacheDir: '/custom/cache',
371368
),
372369
);
373-
const androidBuildInfo = AndroidBuildInfo(buildInfo);
370+
const androidBuildInfo = AndroidBuildInfo(buildInfo, splitPerAbi: true);
374371

375372
expect(androidBuildInfo.toGradleConfig(), <String>[
376373
'-Pdart-defines=${encodeDartDefinesMap(<String, String>{'foo': '2', 'bar': '2'})}',
@@ -386,6 +383,7 @@ void main() {
386383
'-Pfoo=bar',
387384
'-Pfizz=bazz',
388385
'--project-cache-dir=/custom/cache',
386+
'-Psplit-per-abi=true',
389387
]);
390388
});
391389

‎packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,30 @@ void main() {
896896
},
897897
);
898898

899+
testUsingContext(
900+
'getBuildInfo parses AndroidGradleConfig options and populates toGradleConfig',
901+
() async {
902+
final command = DummyAllBuildOptionsFlutterCommand();
903+
await createTestCommandRunner(command).run(<String>[
904+
'dummy',
905+
'--android-project-arg=x=1',
906+
'--android-project-cache-dir=/c',
907+
'--no-android-gradle-daemon',
908+
]);
909+
910+
final BuildInfo buildInfo = await command.getBuildInfo(forcedBuildMode: BuildMode.debug);
911+
expect(buildInfo.androidGradleConfig.gradleDaemon, isFalse);
912+
expect(
913+
AndroidBuildInfo(buildInfo).toGradleConfig(),
914+
containsAll(<String>['-Px=1', '--project-cache-dir=/c']),
915+
);
916+
},
917+
overrides: <Type, Generator>{
918+
FileSystem: () => fileSystem,
919+
ProcessManager: () => processManager,
920+
},
921+
);
922+
899923
testUsingContext(
900924
'getBuildInfo respects historical ExtraFrontEndOptions and ExtraGenSnapshotOptions aliases',
901925
() async {

0 commit comments

Comments
 (0)