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
// 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.
import '../android/android_builder.dart';
import '../android/build_validation.dart';
import '../android/gradle_utils.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 BuildApkCommand extends BuildSubCommand {
BuildApkCommand({bool verboseHelp = false}) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag();
usesTargetOption();
addBuildModeFlags(verboseHelp: verboseHelp);
usesFlavorOption();
usesPubOption();
usesBuildNumberOption();
usesBuildNameOption();
addShrinkingFlag(verboseHelp: verboseHelp);
addSplitDebugInfoOption();
addDartObfuscationOption();
usesDartDefineOption();
usesExtraDartFlagOptions(verboseHelp: verboseHelp);
addBundleSkSLPathOption(hide: !verboseHelp);
addEnableExperimentation(hide: !verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp);
addNullSafetyModeOptions(hide: !verboseHelp);
usesAnalyzeSizeFlag();
addAndroidSpecificBuildOptions(hide: !verboseHelp);
addMultidexOption();
addIgnoreDeprecationOption();
argParser
..addFlag('split-per-abi',
negatable: false,
help: 'Whether to split the APKs per ABIs. '
'To learn more, see: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split',
)
..addMultiOption('target-platform',
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 app is compiled.',
);
usesTrackWidgetCreation(verboseHelp: verboseHelp);
}
@override
final String name = 'apk';
@override
DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
DevelopmentArtifact.androidGenSnapshot,
};
@override
final String description = 'Build an Android APK file from your app.\n\n'
"This command can build debug and release versions of your application. 'debug' builds support "
"debugging and a quick development cycle. 'release' builds don't support debugging and are "
'suitable for deploying to app stores. If you are deploying the app to the Play Store, '
"it's recommended to use app bundles or split the APK to reduce the APK size. Learn more at:\n\n"
' * https://developer.android.com/guide/app-bundle\n'
' * https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split';
@override
Future<CustomDimensions> get usageValues async {
String buildMode;
if (boolArgDeprecated('release')) {
buildMode = 'release';
} else if (boolArgDeprecated('debug')) {
buildMode = 'debug';
} else if (boolArgDeprecated('profile')) {
buildMode = 'profile';
} else {
// The build defaults to release.
buildMode = 'release';
}
return CustomDimensions(
commandBuildApkTargetPlatform: stringsArg('target-platform').join(','),
commandBuildApkBuildMode: buildMode,
commandBuildApkSplitPerAbi: boolArgDeprecated('split-per-abi'),
);
}
@override
Future<FlutterCommandResult> runCommand() async {
if (globals.androidSdk == null) {
exitWithNoSdkMessage();
}
final BuildInfo buildInfo = await getBuildInfo();
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(
buildInfo,
splitPerAbi: boolArgDeprecated('split-per-abi'),
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
multidexEnabled: boolArgDeprecated('multidex'),
);
validateBuild(androidBuildInfo);
displayNullSafetyMode(androidBuildInfo.buildInfo);
globals.terminal.usesTerminalUi = true;
await androidBuilder?.buildApk(
project: FlutterProject.current(),
target: targetFile,
androidBuildInfo: androidBuildInfo,
);
return FlutterCommandResult.success();
}
}