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
f098de1f
Unverified
Commit
f098de1f
authored
Sep 11, 2019
by
Emmanuel Garcia
Committed by
GitHub
Sep 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable Proguard by default on release mode (#39986)
parent
362cde43
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
586 additions
and
122 deletions
+586
-122
flutter.gradle
packages/flutter_tools/gradle/flutter.gradle
+32
-10
flutter_proguard_rules.pro
packages/flutter_tools/gradle/flutter_proguard_rules.pro
+11
-0
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+68
-42
build_info.dart
packages/flutter_tools/lib/src/build_info.dart
+4
-0
build_apk.dart
packages/flutter_tools/lib/src/commands/build_apk.dart
+9
-2
build_appbundle.dart
packages/flutter_tools/lib/src/commands/build_appbundle.dart
+8
-1
context_runner.dart
packages/flutter_tools/lib/src/context_runner.dart
+2
-0
channel_test.dart
packages/flutter_tools/test/general.shard/channel_test.dart
+1
-16
build_apk_test.dart
...ter_tools/test/general.shard/commands/build_apk_test.dart
+213
-18
build_appbundle_test.dart
...ols/test/general.shard/commands/build_appbundle_test.dart
+217
-16
upgrade_test.dart
...utter_tools/test/general.shard/commands/upgrade_test.dart
+1
-17
common.dart
packages/flutter_tools/test/src/common.dart
+2
-0
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+18
-0
No files found.
packages/flutter_tools/gradle/flutter.gradle
View file @
f098de1f
...
...
@@ -132,16 +132,6 @@ class FlutterPlugin implements Plugin<Project> {
}
}
// Add custom build types
project
.
android
.
buildTypes
{
profile
{
initWith
debug
if
(
it
.
hasProperty
(
'matchingFallbacks'
))
{
matchingFallbacks
=
[
'debug'
,
'release'
]
}
}
}
String
flutterRootPath
=
resolveProperty
(
project
,
"flutter.sdk"
,
System
.
env
.
FLUTTER_ROOT
)
if
(
flutterRootPath
==
null
)
{
throw
new
GradleException
(
"Flutter SDK not found. Define location with flutter.sdk in the local.properties file or with a FLUTTER_ROOT environment variable."
)
...
...
@@ -154,6 +144,30 @@ class FlutterPlugin implements Plugin<Project> {
String
flutterExecutableName
=
Os
.
isFamily
(
Os
.
FAMILY_WINDOWS
)
?
"flutter.bat"
:
"flutter"
flutterExecutable
=
Paths
.
get
(
flutterRoot
.
absolutePath
,
"bin"
,
flutterExecutableName
).
toFile
();
// Add custom build types.
project
.
android
.
buildTypes
{
profile
{
initWith
debug
if
(
it
.
hasProperty
(
"matchingFallbacks"
))
{
matchingFallbacks
=
[
"debug"
,
"release"
]
}
}
}
if
(
useProguard
(
project
))
{
String
flutterProguardRules
=
Paths
.
get
(
flutterRoot
.
absolutePath
,
"packages"
,
"flutter_tools"
,
"gradle"
,
"flutter_proguard_rules.pro"
)
project
.
android
.
buildTypes
{
release
{
minifyEnabled
true
useProguard
true
// Fallback to `android/app/proguard-rules.pro`.
// This way, custom Proguard rules can be configured as needed.
proguardFiles
project
.
android
.
getDefaultProguardFile
(
"proguard-android.txt"
),
flutterProguardRules
,
"proguard-rules.pro"
}
}
}
if
(
useLocalEngine
(
project
))
{
String
engineOutPath
=
project
.
property
(
'localEngineOut'
)
File
engineOut
=
project
.
file
(
engineOutPath
)
...
...
@@ -375,6 +389,14 @@ class FlutterPlugin implements Plugin<Project> {
return
false
}
private
static
Boolean
useProguard
(
Project
project
)
{
if
(
project
.
hasProperty
(
'proguard'
))
{
return
project
.
property
(
'proguard'
).
toBoolean
()
}
return
false
}
private
static
Boolean
buildPluginAsAar
()
{
return
System
.
getProperty
(
'build-plugins-as-aars'
)
==
'true'
}
...
...
packages/flutter_tools/gradle/flutter_proguard_rules.pro
0 → 100644
View file @
f098de1f
# Prevents `Fragment and FragmentActivity not found`.
# TODO(blasten): Remove once we bring the Maven dependencies.
-
dontwarn
io
.
flutter
.
embedding
.
**
# Build the ephemeral app in a module project.
# Prevents: Warning: library class <plugin-package> depends on program class io.flutter.plugin.**
# This is due to plugins (libraries) depending on the embedding (the program jar)
-
dontwarn
io
.
flutter
.
plugin
.
**
# The android.** package is provided by the OS at runtime.
-
dontwarn
android
.
**
packages/flutter_tools/lib/src/android/gradle.dart
View file @
f098de1f
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/build_info.dart
View file @
f098de1f
...
...
@@ -92,6 +92,7 @@ class AndroidBuildInfo {
AndroidArch
.
arm64_v8a
,
],
this
.
splitPerAbi
=
false
,
this
.
proguard
=
false
,
});
// The build info containing the mode and flavor.
...
...
@@ -104,6 +105,9 @@ class AndroidBuildInfo {
/// will be produced.
final
bool
splitPerAbi
;
/// Whether to enable Proguard on release mode.
final
bool
proguard
;
/// The target platforms for the build.
final
Iterable
<
AndroidArch
>
targetArchs
;
}
...
...
packages/flutter_tools/lib/src/commands/build_apk.dart
View file @
f098de1f
...
...
@@ -25,9 +25,15 @@ class BuildApkCommand extends BuildSubCommand {
argParser
..
addFlag
(
'split-per-abi'
,
negatable:
false
,
help:
'Whether to split the APKs per ABIs.'
help:
'Whether to split the APKs per ABIs.
'
'To learn more, see: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split'
,
)
..
addFlag
(
'proguard'
,
negatable:
true
,
defaultsTo:
true
,
help:
'Whether to enable Proguard on release mode. '
'To learn more, see: https://flutter.dev/docs/deployment/android#enabling-proguard'
,
)
..
addMultiOption
(
'target-platform'
,
splitCommas:
true
,
defaultsTo:
<
String
>[
'android-arm'
,
'android-arm64'
],
...
...
@@ -79,7 +85,8 @@ class BuildApkCommand extends BuildSubCommand {
final
BuildInfo
buildInfo
=
getBuildInfo
();
final
AndroidBuildInfo
androidBuildInfo
=
AndroidBuildInfo
(
buildInfo
,
splitPerAbi:
argResults
[
'split-per-abi'
],
targetArchs:
argResults
[
'target-platform'
].
map
<
AndroidArch
>(
getAndroidArchForName
)
targetArchs:
argResults
[
'target-platform'
].
map
<
AndroidArch
>(
getAndroidArchForName
),
proguard:
argResults
[
'proguard'
],
);
if
(
buildInfo
.
isRelease
&&
!
androidBuildInfo
.
splitPerAbi
&&
androidBuildInfo
.
targetArchs
.
length
>
1
)
{
...
...
packages/flutter_tools/lib/src/commands/build_appbundle.dart
View file @
f098de1f
...
...
@@ -22,6 +22,12 @@ class BuildAppBundleCommand extends BuildSubCommand {
argParser
..
addFlag
(
'track-widget-creation'
,
negatable:
false
,
hide:
!
verboseHelp
)
..
addFlag
(
'proguard'
,
negatable:
true
,
defaultsTo:
true
,
help:
'Whether to enable Proguard on release mode. '
'To learn more, see: https://flutter.dev/docs/deployment/android#enabling-proguard'
,
)
..
addMultiOption
(
'target-platform'
,
splitCommas:
true
,
defaultsTo:
<
String
>[
'android-arm'
,
'android-arm64'
],
...
...
@@ -63,7 +69,8 @@ class BuildAppBundleCommand extends BuildSubCommand {
@override
Future
<
FlutterCommandResult
>
runCommand
()
async
{
final
AndroidBuildInfo
androidBuildInfo
=
AndroidBuildInfo
(
getBuildInfo
(),
targetArchs:
argResults
[
'target-platform'
].
map
<
AndroidArch
>(
getAndroidArchForName
)
targetArchs:
argResults
[
'target-platform'
].
map
<
AndroidArch
>(
getAndroidArchForName
),
proguard:
argResults
[
'proguard'
],
);
await
androidBuilder
.
buildAab
(
project:
FlutterProject
.
current
(),
...
...
packages/flutter_tools/lib/src/context_runner.dart
View file @
f098de1f
...
...
@@ -7,6 +7,7 @@ import 'dart:async';
import
'android/android_sdk.dart'
;
import
'android/android_studio.dart'
;
import
'android/android_workflow.dart'
;
import
'android/gradle.dart'
;
import
'application_package.dart'
;
import
'artifacts.dart'
;
import
'asset.dart'
;
...
...
@@ -89,6 +90,7 @@ Future<T> runInContext<T>(
FuchsiaSdk:
()
=>
FuchsiaSdk
(),
FuchsiaWorkflow:
()
=>
FuchsiaWorkflow
(),
GenSnapshot:
()
=>
const
GenSnapshot
(),
GradleUtils:
()
=>
GradleUtils
(),
HotRunnerConfig:
()
=>
HotRunnerConfig
(),
IMobileDevice:
()
=>
IMobileDevice
(),
IOSDeploy:
()
=>
const
IOSDeploy
(),
...
...
packages/flutter_tools/test/general.shard/channel_test.dart
View file @
f098de1f
...
...
@@ -3,7 +3,6 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
hide
File
;
import
'package:args/command_runner.dart'
;
...
...
@@ -17,21 +16,7 @@ import 'package:process/process.dart';
import
'../src/common.dart'
;
import
'../src/context.dart'
;
Process
createMockProcess
(
{
int
exitCode
=
0
,
String
stdout
=
''
,
String
stderr
=
''
})
{
final
Stream
<
List
<
int
>>
stdoutStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stdout
),
]);
final
Stream
<
List
<
int
>>
stderrStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stderr
),
]);
final
Process
process
=
MockProcess
();
when
(
process
.
stdout
).
thenAnswer
((
_
)
=>
stdoutStream
);
when
(
process
.
stderr
).
thenAnswer
((
_
)
=>
stderrStream
);
when
(
process
.
exitCode
).
thenAnswer
((
_
)
=>
Future
<
int
>.
value
(
exitCode
));
return
process
;
}
import
'../src/mocks.dart'
;
void
main
(
)
{
group
(
'channel'
,
()
{
...
...
packages/flutter_tools/test/general.shard/commands/build_apk_test.dart
View file @
f098de1f
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart
View file @
f098de1f
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/commands/upgrade_test.dart
View file @
f098de1f
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:convert'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
...
...
@@ -17,21 +15,7 @@ import 'package:process/process.dart';
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
Process
createMockProcess
(
{
int
exitCode
=
0
,
String
stdout
=
''
,
String
stderr
=
''
})
{
final
Stream
<
List
<
int
>>
stdoutStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stdout
),
]);
final
Stream
<
List
<
int
>>
stderrStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stderr
),
]);
final
Process
process
=
MockProcess
();
when
(
process
.
stdout
).
thenAnswer
((
_
)
=>
stdoutStream
);
when
(
process
.
stderr
).
thenAnswer
((
_
)
=>
stderrStream
);
when
(
process
.
exitCode
).
thenAnswer
((
_
)
=>
Future
<
int
>.
value
(
exitCode
));
return
process
;
}
import
'../../src/mocks.dart'
;
void
main
(
)
{
group
(
'UpgradeCommandRunner'
,
()
{
...
...
packages/flutter_tools/test/src/common.dart
View file @
f098de1f
...
...
@@ -116,6 +116,8 @@ Future<String> createProject(Directory temp, { List<String> arguments }) async {
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
...
arguments
,
projectPath
]);
// Created `.packages` since it's not created when the flag `--no-pub` is passed.
fs
.
file
(
fs
.
path
.
join
(
projectPath
,
'.packages'
)).
createSync
();
return
projectPath
;
}
...
...
packages/flutter_tools/test/src/mocks.dart
View file @
f098de1f
...
...
@@ -221,6 +221,24 @@ ProcessFactory flakyProcessFactory({
};
}
/// Creates a mock process that returns with the given [exitCode], [stdout] and [stderr].
Process
createMockProcess
(
{
int
exitCode
=
0
,
String
stdout
=
''
,
String
stderr
=
''
})
{
final
Stream
<
List
<
int
>>
stdoutStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stdout
),
]);
final
Stream
<
List
<
int
>>
stderrStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stderr
),
]);
final
Process
process
=
MockBasicProcess
();
when
(
process
.
stdout
).
thenAnswer
((
_
)
=>
stdoutStream
);
when
(
process
.
stderr
).
thenAnswer
((
_
)
=>
stderrStream
);
when
(
process
.
exitCode
).
thenAnswer
((
_
)
=>
Future
<
int
>.
value
(
exitCode
));
return
process
;
}
class
MockBasicProcess
extends
Mock
implements
Process
{}
/// A process that exits successfully with no output and ignores all input.
class
MockProcess
extends
Mock
implements
Process
{
MockProcess
({
...
...
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