Skip to content

Fix reflection error in com.google.android.datatransport.Priority when using aggressive Proguard rules. #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2020

Conversation

mrichards
Copy link
Contributor

The enum's values are accessed via reflection, so aggressive Proguard
rules can cause it to be stripped out.
e.g., #1996

The enum's values are accessed via reflection, so aggressive Proguard
rules can cause it to be stripped out.
e.g., #1996
@mrichards mrichards requested a review from vkryachko September 29, 2020 18:27
@google-cla google-cla bot added the cla: yes Override cla label Sep 29, 2020
@mrichards
Copy link
Contributor Author

@vkryachko Are you aware of other places where reflection is used in datatransport? This rule will fix a Crashlytics customer crash. Could there be similar issues lurking for other SDKs?

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 29, 2020

Binary Size Report

Affected SDKs

  • transport-runtime

    Type Base (aa3c89f) Head (f8335ef3) Diff
    aar 164 kB 164 kB -26 B (-0.0%)
    apk (aggressive) 33.1 kB 33.1 kB -60 B (-0.2%)
    apk (release) 63.1 kB 63.1 kB -24 B (-0.0%)

Test Logs

Notes

Head commit (f8335ef3) is created by Prow via merging commits: aa3c89f 2de2488.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 29, 2020

Coverage Report

Affected SDKs

No changes between base commit (aa3c89f) and head commit (f8335ef3).

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (f8335ef3) is created by Prow via merging commits: aa3c89f 2de2488.

@vkryachko
Copy link
Member

@mrichards I think the underlying issue is the fact that datatransport uses an EnumMap internally, which for reasons beyond my understanding uses reflection, I got burnt by an EnumSet previously and changed it to a plain HashSet. I wonder if a cleaner fix in this case would be to change EnumMap to HashMap in

private static EnumMap<Priority, Integer> PRIORITY_INT_MAP = new EnumMap<>(Priority.class);

EnumMap uses reflection under the hood. Switching to a HashMap removes the
reflection call, so we don't need the Proguard rule keeping `values`
after all.
@mrichards mrichards changed the title Add proguard rule to keep com.google.android.datatransport.Priority. Fix reflection error in com.google.android.datatransport.Priority when using aggressive Proguard rules. Oct 1, 2020
@mrichards
Copy link
Contributor Author

@mrichards ... I wonder if a cleaner fix in this case would be to change EnumMap to HashMap in...

Yes, that worked. See most recent commit.

Copy link
Member

@vkryachko vkryachko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix!

@mrichards mrichards merged commit 690d119 into master Oct 1, 2020
@mrichards mrichards deleted the transport-reflection-fix branch October 1, 2020 17:48
@firebase firebase locked and limited conversation to collaborators Nov 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants