JWTDecode.Android icon indicating copy to clipboard operation
JWTDecode.Android copied to clipboard

Gson R8 proguard rules (java.lang.runtimeexception: missing type parameter.)

Open stevdza-san opened this issue 2 years ago • 8 comments

Checklist

  • [X] I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • [X] I have looked into the API documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] I agree to the terms within the Auth0 Code of Conduct.

Description

I was using val jwt = JWT(tokenId) to retrieve claims from the tokenId, in the release build of my android studio project, along with R8 enabled. However I've received the following error: java.lang.runtimeexception: missing type parameter.

After adding those three lines of code in the proguard-rules.pro, the error disappeared:

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type

I also had to manually add Gson library to my project just to add those rules, since I'm using KotlinX Serialization library. Is there a way for you to add those rules for Gson, when using R8, so that we don't have to?

Reproduction

  1. Enable R8
  2. Retrieve claims from a tokenId with val jwt = JWT(tokenId)

Additional context

No response

JWTDecode.Android version

2.0.2

Android version(s)

33

stevdza-san avatar Dec 06 '23 22:12 stevdza-san

Thank you for the fix, didn't know I was the only one with this issue.

PrimozEqualEyes avatar Dec 15 '23 14:12 PrimozEqualEyes

Thank you! Just got bit by this bug. Unfortunately made it to production 😬 and this post saved the day.

almasmith avatar Jan 09 '24 19:01 almasmith

Ran into this after upgrading to AGP 8 recently; my guess is that (in my case) this is appearing now due to R8 fullMode being enabled by default. https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode has more details

dgelormini avatar Jan 17 '24 21:01 dgelormini

Ran into this after upgrading to AGP 8 recently; my guess is that (in my case) this is appearing now due to R8 fullMode being enabled by default. https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode has more details

It says we have to enable R8's fullMode manually with android.enableR8.fullMode=true in gradle.properties. The first paragraph states that they leave fullMode off by default to ease the migration from ProGuard to R8.

angusryer avatar Jan 18 '24 18:01 angusryer

Ran into this after upgrading to AGP 8 recently; my guess is that (in my case) this is appearing now due to R8 fullMode being enabled by default. https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode has more details

It says we have to enable R8's fullMode manually with android.enableR8.fullMode=true in gradle.properties. The first paragraph states that they leave fullMode off by default to ease the migration from ProGuard to R8.

When upgrading from AGP 7.x to AGP 8.x (which is the update I just did when I encountered this), the docs here say the new default value is true https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes#default-changes

In my case, setting android.enableR8.fullMode=false resolved all the proguard related issues (for now)

dgelormini avatar Jan 18 '24 18:01 dgelormini

Ran into this after upgrading to AGP 8 recently; my guess is that (in my case) this is appearing now due to R8 fullMode being enabled by default. https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#r8-full-mode has more details

It says we have to enable R8's fullMode manually with android.enableR8.fullMode=true in gradle.properties. The first paragraph states that they leave fullMode off by default to ease the migration from ProGuard to R8.

When upgrading from AGP 7.x to AGP 8.x (which is the update I just did when I encountered this), the docs here say the new default value is true https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes#default-changes

In my case, setting android.enableR8.fullMode=false resolved all the proguard related issues (for now)

That's great--thanks for clarifying! I'll see if this change resolves the error for me.

EDIT: It worked. Thank you.

angusryer avatar Jan 18 '24 18:01 angusryer

Any news here? Is this going to be resolved or we need to go with: android.enableR8.fullMode=false?

Kuglll avatar Aug 20 '24 13:08 Kuglll

@stevdza-san I was trying to display the log on the release build.

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type

This solves the error java.lang.IllegalStateException: TypeToken must be created with a type argument: new TypeToken<...>() occurred on com.chuckerteam.chucker.internal.ui.transaction.TransactionPayloadFragment

Thanks.

JustKhit avatar Sep 10 '24 18:09 JustKhit