Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a0745e23
Unverified
Commit
a0745e23
authored
Aug 03, 2020
by
Jonah Williams
Committed by
GitHub
Aug 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] add --analyze-size flag (#62697)
parent
67e9b294
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
0 deletions
+86
-0
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+21
-0
build_info.dart
packages/flutter_tools/lib/src/build_info.dart
+5
-0
build_apk.dart
packages/flutter_tools/lib/src/commands/build_apk.dart
+1
-0
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+24
-0
analyze_size_apk_test.dart
...r_tools/test/integration.shard/analyze_size_apk_test.dart
+35
-0
No files found.
packages/flutter_tools/lib/src/android/gradle.dart
View file @
a0745e23
...
...
@@ -9,6 +9,7 @@ import 'package:meta/meta.dart';
import
'package:xml/xml.dart'
;
import
'../artifacts.dart'
;
import
'../base/analyze_size.dart'
;
import
'../base/common.dart'
;
import
'../base/file_system.dart'
;
import
'../base/io.dart'
;
...
...
@@ -18,6 +19,7 @@ import '../base/terminal.dart';
import
'../base/utils.dart'
;
import
'../build_info.dart'
;
import
'../cache.dart'
;
import
'../convert.dart'
;
import
'../flutter_manifest.dart'
;
import
'../globals.dart'
as
globals
;
import
'../project.dart'
;
...
...
@@ -499,6 +501,25 @@ Future<void> buildGradleApp({
'
$successMark
Built
${globals.fs.path.relative(apkFile.path)}$appSize
.'
,
color:
TerminalColor
.
green
,
);
// Call size analyzer if --analyze-size flag was provided.
if
(
buildInfo
.
analyzeSize
!=
null
&&
!
globals
.
platform
.
isWindows
)
{
final
SizeAnalyzer
sizeAnalyzer
=
SizeAnalyzer
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
processUtils:
ProcessUtils
.
instance
,
);
final
Map
<
String
,
Object
>
output
=
await
sizeAnalyzer
.
analyzeApkSizeAndAotSnapshot
(
apk:
apkFile
,
aotSnapshot:
globals
.
fs
.
file
(
buildInfo
.
analyzeSize
),
);
final
File
outputFile
=
globals
.
fsUtils
.
getUniqueFile
(
globals
.
fs
.
currentDirectory
,
'apk-analysis'
,
'json'
)
..
writeAsStringSync
(
jsonEncode
(
output
));
// This message is used as a sentinel in analyze_apk_size_test.dart
globals
.
printStatus
(
'A summary of your APK analysis can be found at:
${outputFile.path}
'
,
);
}
}
/// Builds AAR and POM files.
...
...
packages/flutter_tools/lib/src/build_info.dart
View file @
a0745e23
...
...
@@ -33,6 +33,7 @@ class BuildInfo {
this
.
performanceMeasurementFile
,
this
.
packagesPath
=
'.packages'
,
this
.
nullSafetyMode
=
NullSafetyMode
.
autodetect
,
this
.
analyzeSize
,
});
final
BuildMode
mode
;
...
...
@@ -113,6 +114,10 @@ class BuildInfo {
/// rerun tasks.
final
String
performanceMeasurementFile
;
/// If provided, an output file where a v8-style heapsnapshot will be written for size
/// profiling.
final
String
analyzeSize
;
static
const
BuildInfo
debug
=
BuildInfo
(
BuildMode
.
debug
,
null
,
treeShakeIcons:
false
);
static
const
BuildInfo
profile
=
BuildInfo
(
BuildMode
.
profile
,
null
,
treeShakeIcons:
kIconTreeShakerEnabledDefault
);
static
const
BuildInfo
jitRelease
=
BuildInfo
(
BuildMode
.
jitRelease
,
null
,
treeShakeIcons:
kIconTreeShakerEnabledDefault
);
...
...
packages/flutter_tools/lib/src/commands/build_apk.dart
View file @
a0745e23
...
...
@@ -34,6 +34,7 @@ class BuildApkCommand extends BuildSubCommand {
addEnableExperimentation
(
hide:
!
verboseHelp
);
addBuildPerformanceFile
(
hide:
!
verboseHelp
);
addNullSafetyModeOptions
(
hide:
!
verboseHelp
);
usesAnalyzeSizeFlag
();
argParser
..
addFlag
(
'split-per-abi'
,
negatable:
false
,
...
...
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
a0745e23
...
...
@@ -112,6 +112,7 @@ class FlutterOptions {
static
const
String
kPerformanceMeasurementFile
=
'performance-measurement-file'
;
static
const
String
kNullSafety
=
'sound-null-safety'
;
static
const
String
kDeviceUser
=
'device-user'
;
static
const
String
kAnalyzeSize
=
'analyze-size'
;
}
abstract
class
FlutterCommand
extends
Command
<
void
>
{
...
...
@@ -605,6 +606,15 @@ abstract class FlutterCommand extends Command<void> {
);
}
void
usesAnalyzeSizeFlag
()
{
argParser
.
addFlag
(
FlutterOptions
.
kAnalyzeSize
,
defaultsTo:
false
,
help:
'Whether to produce additonal profile information for artifact output size. '
'This flag is only support on release builds on macOS/Linux hosts.'
);
}
/// Compute the [BuildInfo] for the current flutter command.
/// Commands that build multiple build modes can pass in a [forcedBuildMode]
/// to be used instead of parsing flags.
...
...
@@ -640,6 +650,15 @@ abstract class FlutterCommand extends Command<void> {
}
}
String
analyzeSize
;
if
(
argParser
.
options
.
containsKey
(
FlutterOptions
.
kAnalyzeSize
)
&&
boolArg
(
FlutterOptions
.
kAnalyzeSize
)
&&
!
globals
.
platform
.
isWindows
)
{
final
File
file
=
globals
.
fsUtils
.
getUniqueFile
(
globals
.
fs
.
currentDirectory
,
'flutter_size'
,
'json'
);
extraGenSnapshotOptions
.
add
(
'--write-v8-snapshot-profile-to=
${file.path}
'
);
analyzeSize
=
file
.
path
;
}
NullSafetyMode
nullSafetyMode
=
NullSafetyMode
.
unsound
;
if
(
argParser
.
options
.
containsKey
(
FlutterOptions
.
kNullSafety
))
{
final
bool
nullSafety
=
boolArg
(
FlutterOptions
.
kNullSafety
);
...
...
@@ -671,6 +690,10 @@ abstract class FlutterCommand extends Command<void> {
);
}
final
BuildMode
buildMode
=
forcedBuildMode
??
getBuildMode
();
if
(
buildMode
!=
BuildMode
.
release
&&
analyzeSize
!=
null
)
{
throwToolExit
(
'--analyze-size can only be used on release builds.'
);
}
final
bool
treeShakeIcons
=
argParser
.
options
.
containsKey
(
'tree-shake-icons'
)
&&
buildMode
.
isPrecompiled
&&
boolArg
(
'tree-shake-icons'
);
...
...
@@ -715,6 +738,7 @@ abstract class FlutterCommand extends Command<void> {
performanceMeasurementFile:
performanceMeasurementFile
,
packagesPath:
globalResults
[
'packages'
]
as
String
??
'.packages'
,
nullSafetyMode:
nullSafetyMode
,
analyzeSize:
analyzeSize
,
);
}
...
...
packages/flutter_tools/test/integration.shard/analyze_size_apk_test.dart
0 → 100644
View file @
a0745e23
// 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
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:process/process.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'../src/common.dart'
;
const
String
debugMessage
=
'A summary of your APK analysis can be found at: '
;
void
main
(
)
{
test
(
'--analyze-size flag produces expected output on hello_world'
,
()
async
{
final
String
flutterBin
=
globals
.
fs
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
'flutter'
);
final
ProcessResult
result
=
await
const
LocalProcessManager
().
run
(<
String
>[
flutterBin
,
'build'
,
'apk'
,
'--analyze-size'
,
],
workingDirectory:
globals
.
fs
.
path
.
join
(
getFlutterRoot
(),
'examples'
,
'hello_world'
));
print
(
result
.
stdout
);
print
(
result
.
stderr
);
expect
(
result
.
stdout
.
toString
(),
contains
(
'app-release.apk (total compressed)'
));
final
String
line
=
result
.
stdout
.
toString
()
.
split
(
'
\n
'
)
.
firstWhere
((
String
line
)
=>
line
.
contains
(
debugMessage
));
expect
(
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
line
.
split
(
debugMessage
).
last
.
trim
())).
existsSync
(),
true
);
expect
(
result
.
exitCode
,
0
);
},
skip:
const
LocalPlatform
().
isWindows
);
// Not yet supported on Windows
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment