JWTDecode.Android
JWTDecode.Android copied to clipboard
Gson R8 proguard rules (java.lang.runtimeexception: missing type parameter.)
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
- Enable R8
- Retrieve claims from a tokenId with
val jwt = JWT(tokenId)
Additional context
No response
JWTDecode.Android version
2.0.2
Android version(s)
33
Thank you for the fix, didn't know I was the only one with this issue.
Thank you! Just got bit by this bug. Unfortunately made it to production 😬 and this post saved the day.
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
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.
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=trueingradle.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)
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=trueingradle.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
truehttps://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes#default-changesIn my case, setting
android.enableR8.fullMode=falseresolved 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.
Any news here? Is this going to be resolved or we need to go with:
android.enableR8.fullMode=false?
@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.