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
0df1594b
Unverified
Commit
0df1594b
authored
Sep 16, 2019
by
Emmanuel Garcia
Committed by
GitHub
Sep 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable the resource shrinker (#40610)
parent
26bb9314
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
5 deletions
+90
-5
test.dart
dev/bots/test.dart
+1
-0
gradle_r8_test.dart
dev/devicelab/bin/tasks/gradle_r8_test.dart
+77
-0
flutter.gradle
packages/flutter_tools/gradle/flutter.gradle
+12
-5
No files found.
dev/bots/test.dart
View file @
0df1594b
...
@@ -1018,6 +1018,7 @@ Future<void> _androidGradleTests(String subShard) async {
...
@@ -1018,6 +1018,7 @@ Future<void> _androidGradleTests(String subShard) async {
if
(
subShard
==
'gradle1'
)
{
if
(
subShard
==
'gradle1'
)
{
await
_runDevicelabTest
(
'gradle_plugin_light_apk_test'
,
env:
env
);
await
_runDevicelabTest
(
'gradle_plugin_light_apk_test'
,
env:
env
);
await
_runDevicelabTest
(
'gradle_plugin_fat_apk_test'
,
env:
env
);
await
_runDevicelabTest
(
'gradle_plugin_fat_apk_test'
,
env:
env
);
await
_runDevicelabTest
(
'gradle_r8_test'
,
env:
env
);
}
}
if
(
subShard
==
'gradle2'
)
{
if
(
subShard
==
'gradle2'
)
{
await
_runDevicelabTest
(
'gradle_plugin_bundle_test'
,
env:
env
);
await
_runDevicelabTest
(
'gradle_plugin_bundle_test'
,
env:
env
);
...
...
dev/devicelab/bin/tasks/gradle_r8_test.dart
0 → 100644
View file @
0df1594b
// Copyright (c) 2019 The Chromium 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
'dart:async'
;
import
'dart:io'
;
import
'package:flutter_devicelab/framework/framework.dart'
;
import
'package:flutter_devicelab/framework/utils.dart'
;
import
'package:path/path.dart'
as
path
;
/// Tests that flutter build apk uses R8 by default by adding an
/// invalid proguard rule and evaluating the error message.
Future
<
void
>
main
()
async
{
await
task
(()
async
{
section
(
'Find Java'
);
final
String
javaHome
=
await
findJavaHome
();
if
(
javaHome
==
null
)
return
TaskResult
.
failure
(
'Could not find Java'
);
print
(
'
\n
Using JAVA_HOME=
$javaHome
'
);
section
(
'Create Flutter app project'
);
final
Directory
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_module_test.'
);
final
Directory
projectDir
=
Directory
(
path
.
join
(
tempDir
.
path
,
'hello'
));
try
{
await
inDirectory
(
tempDir
,
()
async
{
await
flutter
(
'create'
,
options:
<
String
>[
'--org'
,
'io.flutter.devicelab'
,
'hello'
,
],
);
});
section
(
'Add incorrect proguard rules'
);
final
File
proguardRules
=
File
(
path
.
join
(
projectDir
.
path
,
'android'
,
'app'
,
'proguard-rules.pro'
,
));
proguardRules
.
writeAsStringSync
(
'invalidRule'
,
flush:
true
);
section
(
'Build release APK'
);
final
StringBuffer
stderr
=
StringBuffer
();
await
inDirectory
(
projectDir
,
()
async
{
await
evalFlutter
(
'build'
,
options:
<
String
>[
'apk'
,
'--target-platform'
,
'android-arm'
,
'--verbose'
,
],
canFail:
true
,
stderr:
stderr
,
);
});
if
(!
stderr
.
toString
().
contains
(
'com.android.tools.r8.CompilationFailedException'
))
{
return
TaskResult
.
failure
(
'Expected com.android.tools.r8.CompilationFailedException in stderr.'
);
}
return
TaskResult
.
success
(
null
);
}
catch
(
e
)
{
return
TaskResult
.
failure
(
e
.
toString
());
}
finally
{
rmTree
(
tempDir
);
}
});
}
packages/flutter_tools/gradle/flutter.gradle
View file @
0df1594b
...
@@ -154,7 +154,7 @@ class FlutterPlugin implements Plugin<Project> {
...
@@ -154,7 +154,7 @@ class FlutterPlugin implements Plugin<Project> {
}
}
}
}
if
(
should
UseProguard
(
project
))
{
if
(
should
ShrinkResources
(
project
))
{
String
flutterProguardRules
=
Paths
.
get
(
flutterRoot
.
absolutePath
,
"packages"
,
"flutter_tools"
,
String
flutterProguardRules
=
Paths
.
get
(
flutterRoot
.
absolutePath
,
"packages"
,
"flutter_tools"
,
"gradle"
,
"flutter_proguard_rules.pro"
)
"gradle"
,
"flutter_proguard_rules.pro"
)
project
.
android
.
buildTypes
{
project
.
android
.
buildTypes
{
...
@@ -164,7 +164,8 @@ class FlutterPlugin implements Plugin<Project> {
...
@@ -164,7 +164,8 @@ class FlutterPlugin implements Plugin<Project> {
minifyEnabled
true
minifyEnabled
true
// Enables resource shrinking, which is performed by the
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
// Android Gradle plugin.
shrinkResources
true
// NOTE: The resource shrinker can't be used for libraries.
shrinkResources
isBuiltAsApp
(
project
)
// Fallback to `android/app/proguard-rules.pro`.
// Fallback to `android/app/proguard-rules.pro`.
// This way, custom Proguard rules can be configured as needed.
// This way, custom Proguard rules can be configured as needed.
proguardFiles
project
.
android
.
getDefaultProguardFile
(
"proguard-android.txt"
),
flutterProguardRules
,
"proguard-rules.pro"
proguardFiles
project
.
android
.
getDefaultProguardFile
(
"proguard-android.txt"
),
flutterProguardRules
,
"proguard-rules.pro"
...
@@ -393,13 +394,19 @@ class FlutterPlugin implements Plugin<Project> {
...
@@ -393,13 +394,19 @@ class FlutterPlugin implements Plugin<Project> {
return
false
return
false
}
}
private
static
Boolean
should
UseProguard
(
Project
project
)
{
private
static
Boolean
should
ShrinkResources
(
Project
project
)
{
if
(
project
.
hasProperty
(
'proguard'
))
{
if
(
project
.
hasProperty
(
"shrink"
))
{
return
project
.
property
(
'proguard'
).
toBoolean
()
return
project
.
property
(
"shrink"
).
toBoolean
()
}
}
return
false
return
false
}
}
private
static
Boolean
isBuiltAsApp
(
Project
project
)
{
// Projects are built as applications when the they use the `com.android.application`
// plugin.
return
project
.
plugins
.
hasPlugin
(
"com.android.application"
);
}
private
static
Boolean
buildPluginAsAar
()
{
private
static
Boolean
buildPluginAsAar
()
{
return
System
.
getProperty
(
'build-plugins-as-aars'
)
==
'true'
return
System
.
getProperty
(
'build-plugins-as-aars'
)
==
'true'
}
}
...
...
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