@@ -7,6 +7,7 @@ import 'dart:math';
7
7
import 'package:crypto/crypto.dart' ;
8
8
import 'package:meta/meta.dart' ;
9
9
import 'package:process/process.dart' ;
10
+ import 'package:unified_analytics/unified_analytics.dart' ;
10
11
import 'package:xml/xml.dart' ;
11
12
12
13
import '../artifacts.dart' ;
@@ -149,6 +150,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
149
150
required FileSystem fileSystem,
150
151
required Artifacts artifacts,
151
152
required Usage usage,
153
+ required Analytics analytics,
152
154
required GradleUtils gradleUtils,
153
155
required Platform platform,
154
156
required AndroidStudio ? androidStudio,
@@ -157,6 +159,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
157
159
_fileSystem = fileSystem,
158
160
_artifacts = artifacts,
159
161
_usage = usage,
162
+ _analytics = analytics,
160
163
_gradleUtils = gradleUtils,
161
164
_androidStudio = androidStudio,
162
165
_fileSystemUtils = FileSystemUtils (fileSystem: fileSystem, platform: platform),
@@ -168,6 +171,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
168
171
final FileSystem _fileSystem;
169
172
final Artifacts _artifacts;
170
173
final Usage _usage;
174
+ final Analytics _analytics;
171
175
final GradleUtils _gradleUtils;
172
176
final FileSystemUtils _fileSystemUtils;
173
177
final AndroidStudio ? _androidStudio;
@@ -300,7 +304,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
300
304
@visibleForTesting int ? maxRetries,
301
305
}) async {
302
306
if (! project.android.isSupportedVersion) {
303
- _exitWithUnsupportedProjectMessage (_usage, _logger.terminal);
307
+ _exitWithUnsupportedProjectMessage (_usage, _logger.terminal, analytics : _analytics );
304
308
}
305
309
306
310
final List <ProjectMigrator > migrators = < ProjectMigrator > [
@@ -318,8 +322,11 @@ class AndroidGradleBuilder implements AndroidBuilder {
318
322
final bool usesAndroidX = isAppUsingAndroidX (project.android.hostAppGradleRoot);
319
323
if (usesAndroidX) {
320
324
BuildEvent ('app-using-android-x' , type: 'gradle' , flutterUsage: _usage).send ();
325
+ _analytics.send (Event .flutterBuildInfo (label: 'app-using-android-x' , buildType: 'gradle' ));
321
326
} else if (! usesAndroidX) {
322
327
BuildEvent ('app-not-using-android-x' , type: 'gradle' , flutterUsage: _usage).send ();
328
+ _analytics.send (Event .flutterBuildInfo (label: 'app-not-using-android-x' , buildType: 'gradle' ));
329
+
323
330
_logger.printStatus ("${_logger .terminal .warningMark } Your app isn't using AndroidX." , emphasis: true );
324
331
_logger.printStatus (
325
332
'To avoid potential build failures, you can quickly migrate your app '
@@ -488,6 +495,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
488
495
if (exitCode != 0 ) {
489
496
if (detectedGradleError == null ) {
490
497
BuildEvent ('gradle-unknown-failure' , type: 'gradle' , flutterUsage: _usage).send ();
498
+ _analytics.send (Event .flutterBuildInfo (label: 'gradle-unknown-failure' , buildType: 'gradle' ));
499
+
491
500
throwToolExit (
492
501
'Gradle task $assembleTask failed with exit code $exitCode ' ,
493
502
exitCode: exitCode,
@@ -520,21 +529,27 @@ class AndroidGradleBuilder implements AndroidBuilder {
520
529
configOnly: configOnly,
521
530
);
522
531
final String successEventLabel = 'gradle-${detectedGradleError !.eventLabel }-success' ;
532
+
523
533
BuildEvent (successEventLabel, type: 'gradle' , flutterUsage: _usage).send ();
534
+ _analytics.send (Event .flutterBuildInfo (label: successEventLabel, buildType: 'gradle' ));
535
+
524
536
return ;
525
537
case GradleBuildStatus .exit:
526
538
// Continue and throw tool exit.
527
539
}
528
540
}
529
- BuildEvent ('gradle-${detectedGradleError ?.eventLabel }-failure' , type: 'gradle' , flutterUsage: _usage).send ();
541
+ final String usageLabel = 'gradle-${detectedGradleError ?.eventLabel }-failure' ;
542
+ BuildEvent (usageLabel, type: 'gradle' , flutterUsage: _usage).send ();
543
+ _analytics.send (Event .flutterBuildInfo (label: usageLabel, buildType: 'gradle' ));
544
+
530
545
throwToolExit (
531
546
'Gradle task $assembleTask failed with exit code $exitCode ' ,
532
547
exitCode: exitCode,
533
548
);
534
549
}
535
550
536
551
if (isBuildingBundle) {
537
- final File bundleFile = findBundleFile (project, buildInfo, _logger, _usage);
552
+ final File bundleFile = findBundleFile (project, buildInfo, _logger, _usage, _analytics );
538
553
final String appSize = (buildInfo.mode == BuildMode .debug)
539
554
? '' // Don't display the size when building a debug variant.
540
555
: ' (${getSizeAsMB (bundleFile .lengthSync ())})' ;
@@ -551,7 +566,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
551
566
}
552
567
// Gradle produced APKs.
553
568
final Iterable <String > apkFilesPaths = project.isModule
554
- ? findApkFilesModule (project, androidBuildInfo, _logger, _usage)
569
+ ? findApkFilesModule (project, androidBuildInfo, _logger, _usage, _analytics )
555
570
: listApkPaths (androidBuildInfo);
556
571
final Directory apkDirectory = getApkDirectory (project);
557
572
@@ -563,6 +578,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
563
578
fileExtension: '.apk' ,
564
579
logger: _logger,
565
580
usage: _usage,
581
+ analytics: _analytics,
566
582
);
567
583
}
568
584
@@ -886,8 +902,14 @@ String _calculateSha(File file) {
886
902
return _hex (sha1.convert (bytes).bytes);
887
903
}
888
904
889
- void _exitWithUnsupportedProjectMessage (Usage usage, Terminal terminal) {
905
+ void _exitWithUnsupportedProjectMessage (Usage usage, Terminal terminal, { required Analytics analytics} ) {
890
906
BuildEvent ('unsupported-project' , type: 'gradle' , eventError: 'gradle-plugin' , flutterUsage: usage).send ();
907
+ analytics.send (Event .flutterBuildInfo (
908
+ label: 'unsupported-project' ,
909
+ buildType: 'gradle' ,
910
+ error: 'gradle-plugin' ,
911
+ ));
912
+
891
913
throwToolExit (
892
914
'${terminal .warningMark } Your app is using an unsupported Gradle project. '
893
915
'To fix this problem, create a new project by running `flutter create -t app <app-directory>` '
@@ -913,6 +935,7 @@ Iterable<String> findApkFilesModule(
913
935
AndroidBuildInfo androidBuildInfo,
914
936
Logger logger,
915
937
Usage usage,
938
+ Analytics analytics,
916
939
) {
917
940
final Iterable <String > apkFileNames = _apkFilesFor (androidBuildInfo);
918
941
final Directory apkDirectory = getApkDirectory (project);
@@ -948,6 +971,7 @@ Iterable<String> findApkFilesModule(
948
971
fileExtension: '.apk' ,
949
972
logger: logger,
950
973
usage: usage,
974
+ analytics: analytics,
951
975
);
952
976
}
953
977
return apks.map ((File file) => file.path);
@@ -986,7 +1010,7 @@ Iterable<String> listApkPaths(
986
1010
}
987
1011
988
1012
@visibleForTesting
989
- File findBundleFile (FlutterProject project, BuildInfo buildInfo, Logger logger, Usage usage) {
1013
+ File findBundleFile (FlutterProject project, BuildInfo buildInfo, Logger logger, Usage usage, Analytics analytics ) {
990
1014
final List <File > fileCandidates = < File > [
991
1015
getBundleDirectory (project)
992
1016
.childDirectory (camelCase (buildInfo.modeName))
@@ -1043,6 +1067,7 @@ File findBundleFile(FlutterProject project, BuildInfo buildInfo, Logger logger,
1043
1067
fileExtension: '.aab' ,
1044
1068
logger: logger,
1045
1069
usage: usage,
1070
+ analytics: analytics,
1046
1071
);
1047
1072
}
1048
1073
@@ -1052,17 +1077,25 @@ Never _exitWithExpectedFileNotFound({
1052
1077
required String fileExtension,
1053
1078
required Logger logger,
1054
1079
required Usage usage,
1080
+ required Analytics analytics,
1055
1081
}) {
1056
1082
1057
1083
final String androidGradlePluginVersion =
1058
1084
getGradleVersionForAndroidPlugin (project.android.hostAppGradleRoot, logger);
1085
+ final String gradleBuildSettings = 'androidGradlePluginVersion: $androidGradlePluginVersion , '
1086
+ 'fileExtension: $fileExtension ' ;
1087
+
1059
1088
BuildEvent ('gradle-expected-file-not-found' ,
1060
1089
type: 'gradle' ,
1061
- settings:
1062
- 'androidGradlePluginVersion: $androidGradlePluginVersion , '
1063
- 'fileExtension: $fileExtension ' ,
1090
+ settings: gradleBuildSettings,
1064
1091
flutterUsage: usage,
1065
1092
).send ();
1093
+ analytics.send (Event .flutterBuildInfo (
1094
+ label: 'gradle-expected-file-not-found' ,
1095
+ buildType: 'gradle' ,
1096
+ settings: gradleBuildSettings,
1097
+ ));
1098
+
1066
1099
throwToolExit (
1067
1100
'Gradle build failed to produce an $fileExtension file. '
1068
1101
"It's likely that this file was generated under ${project .android .buildDirectory .path }, "
0 commit comments