Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
[ID: 558956]
View issue level access limits(Press Alt + Right arrow for more information)
Attachment actions
Unintended behavior
View staffing
Description
During migration from Android Gradle Plugin 3.4.2 to 4.0.1 our team noticed a strange side effect. Consider the following example:
Let's take a look at the bytecode.
The main difference between those outputs is that R8 used in AGP 4.0.1 inlines listener field while R8 bundled with AGP 3.4.2 doesn't. It becomes an issue if we rely on that field to be present. For example, consider the following implementation of ConfigurationHandler:
As you can see, if we remove the private field(listener) there is a chance that GC will collect WeakReference. That kind of behavior is unexpected and can lead to some hard to reproduce bugs.
Currently, we are using specific proguard rule to avoid that behavior:
Which is working fine, even though it seems a bit broad because it also keeps fully unused fields.
There is a reproducible sample attached.