1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../android/android_builder.dart';
import '../android/gradle_utils.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/os.dart';
import '../build_info.dart';
import '../cache.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../reporting/reporting.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';
class BuildAarCommand extends BuildSubCommand {
BuildAarCommand({ @required bool verboseHelp }) {
argParser
..addFlag(
'debug',
defaultsTo: true,
help: 'Build a debug version of the current project.',
)
..addFlag(
'profile',
defaultsTo: true,
help: 'Build a version of the current project specialized for performance profiling.',
)
..addFlag(
'release',
defaultsTo: true,
help: 'Build a release version of the current project.',
);
addTreeShakeIconsFlag();
usesFlavorOption();
usesBuildNumberOption();
usesPubOption();
addSplitDebugInfoOption();
addDartObfuscationOption();
usesDartDefineOption();
usesTrackWidgetCreation(verboseHelp: false);
addNullSafetyModeOptions(hide: !verboseHelp);
addEnableExperimentation(hide: !verboseHelp);
addAndroidSpecificBuildOptions(hide: !verboseHelp);
argParser
..addMultiOption(
'target-platform',
splitCommas: true,
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'],
help: 'The target platform for which the project is compiled.',
)
..addOption(
'output-dir',
help: 'The absolute path to the directory where the repository is generated. '
'By default, this is "<current-directory>android/build".',
);
}
@override
final String name = 'aar';
@override
bool get reportNullSafety => false;
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
DevelopmentArtifact.androidGenSnapshot,
};
@override
Future<CustomDimensions> get usageValues async {
final FlutterProject flutterProject = _getProject();
if (flutterProject == null) {
return const CustomDimensions();
}
String projectType;
if (flutterProject.manifest.isModule) {
projectType = 'module';
} else if (flutterProject.manifest.isPlugin) {
projectType = 'plugin';
} else {
projectType = 'app';
}
return CustomDimensions(
commandBuildAarProjectType: projectType,
commandBuildAarTargetPlatform: stringsArg('target-platform').join(','),
);
}
@override
final String description = 'Build a repository containing an AAR and a POM file.\n\n'
'By default, AARs are built for `release`, `debug` and `profile`.\n'
'The POM file is used to include the dependencies that the AAR was compiled against.\n'
'To learn more about how to use these artifacts, see '
'https://flutter.dev/go/build-aar\n'
'Note: this command builds applications assuming that the entrypoint is lib/main.dart. '
'This cannot currently be configured.';
@override
Future<FlutterCommandResult> runCommand() async {
if (globals.androidSdk == null) {
exitWithNoSdkMessage();
}
final Set<AndroidBuildInfo> androidBuildInfo = <AndroidBuildInfo>{};
final Iterable<AndroidArch> targetArchitectures =
stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName);
final String buildNumber = argParser.options.containsKey('build-number')
&& stringArg('build-number') != null
&& stringArg('build-number').isNotEmpty
? stringArg('build-number')
: '1.0';
final File targetFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'));
for (final String buildMode in const <String>['debug', 'profile', 'release']) {
if (boolArg(buildMode)) {
androidBuildInfo.add(
AndroidBuildInfo(
await getBuildInfo(
forcedBuildMode: BuildMode.fromName(buildMode),
forcedTargetFile: targetFile,
),
targetArchs: targetArchitectures,
)
);
}
}
if (androidBuildInfo.isEmpty) {
throwToolExit('Please specify a build mode and try again.');
}
displayNullSafetyMode(androidBuildInfo.first.buildInfo);
await androidBuilder.buildAar(
project: _getProject(),
target: targetFile.path,
androidBuildInfo: androidBuildInfo,
outputDirectoryPath: stringArg('output-dir'),
buildNumber: buildNumber,
);
return FlutterCommandResult.success();
}
/// Returns the [FlutterProject] which is determined from the remaining command-line
/// argument if any or the current working directory.
FlutterProject _getProject() {
if (argResults.rest.isEmpty) {
return FlutterProject.current();
}
return FlutterProject.fromDirectory(globals.fs.directory(findProjectRoot(globals.fs, argResults.rest.first)));
}
}