Skip to content

com.google.common.reflect.TypeToken isn't parameterizedΒ #3

@SebastianEngel

Description

@SebastianEngel

Hi,

after upgrading to Android Gradle Plugin version 8, R8 fullmode is now enabled by default, which brings more aggressive optimizations. Because of that running our app results in the following error:

E/Android: [Awesome Notifications](12551): class com.google.common.reflect.TypeToken isn't parameterized (SharedManager:58)
W/System.err(12551): me.carda.awesome_notifications.core.exceptions.AwesomeNotificationsException: class com.google.common.reflect.TypeToken isn't parameterized
W/System.err(12551): 	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:218)
W/System.err(12551): 	at com.google.common.reflect.TypeCapture.capture(TypeCapture.java:33)
W/System.err(12551): 	at com.google.common.reflect.TypeToken.<init>(TypeToken.java:125)
W/System.err(12551): 	at me.carda.awesome_notifications.core.utils.JsonUtils$1.<init>(JsonUtils.java:19)
W/System.err(12551): 	at me.carda.awesome_notifications.core.utils.JsonUtils.fromJson(JsonUtils.java:19)

I investigated and found that adding the following lines to the proguard config would help:

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

I also saw that those are already in the AndroidAwnCore's proguardrules.pro file.

I assume that the error still occurs because the JsonUtils class mentioned in the stacktrace actually imports com.google.common.reflect.TypeToken, not import com.google.common.gson.TypeToken as defined in the proguard keep rules. Therefore I assume the keep rules need to be adjusted to the match the com.google.common.reflect.TypeToken import OR the import in JsonUtils needs to be changed to match the current keep rules for com.google.common.gson.TypeToken.

A similar case was reported in the Android issue tracker. There they solved it with wildcard usages for the keep rules.

-keep,allowshrinking class **.reflect.TypeToken { *; }
-keep,allowshrinking class * extends **.reflect.TypeToken

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions