Enable Proguard by default on release mode#39986
Conversation
Codecov Report
@@ Coverage Diff @@
## master #39986 +/- ##
==========================================
- Coverage 58.56% 58.33% -0.24%
==========================================
Files 192 194 +2
Lines 18443 18749 +306
==========================================
+ Hits 10801 10937 +136
- Misses 7642 7812 +170
Continue to review full report at Codecov.
|
|
Now I just realized that coverage report has false positives. The decreased coverage in some files is just the result of moving code, so it can be reused. |
dnfield
left a comment
There was a problem hiding this comment.
couple nits - was there some reason we didn't enable this in the past? I was under the impression it could be destructive in some way for plugins that would be non-obvious for new users. I see a way to override that for plugins here, but will that be something that (new) users will be able to understand and use correctly?
|
If Proguard failed, the tool will log the event and tell the user to use If we detect that a lot of folks are seeing warnings from Proguard, we could flip the default value and scoped down the issues. For instance: #37839. |
|
Wouldn't the failure potentially happen at runtime though? E.g. if proguard removed a class you actually want to use but it thought was safe to remove. |
|
@dnfield I can only think of JNI calls or reflection. This won't be an issue in the engine since the rules are configured, but if a plugin is doing something similar then that plugin should use the |
|
I'm not sure about any plugins using reflection. I may be mis-remembering, but I had a vague notion that the way we do the plugin registration could end up having proguard shake out plugin code we want to keep. Is there a test that covers this flag with a plugin enabled? |
yes, the Flutter gallery. I also tested manually and on Firebase device lab.
AFAICT, |
packages/flutter_tools/test/general.shard/commands/build_apk_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart
Outdated
Show resolved
Hide resolved
|
This broke my build: |
|
@rostopira what version of Gradle and the Android Gradle plugin are you using? This issue is being discussed on #40213 |

Description
Add
--proguardflag toflutter build apkandflutter build appbundleand enable it by default for release builts.This change makes it possible to add custom rules by placing the file
proguard-rules.proin theandroid/directory in case a plugin requires special rules.Size in bytes
cc @Hixie
Related Issues
Fixes #11099
Tests
build_apk_test.dart
build_appbundle_test.dart
These tests aren't hermetic yet, but these are the first ones to test the calls to Gradle.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?