6

My project encountered this error:

enter image description here

I tried to fix it using this link

but I can not because I do not really understand the answer. Please tell me how to fix it. Thanks

cigien
  • 57,834
  • 11
  • 73
  • 112
Tâm Lê
  • 107
  • 1
  • 6

2 Answers2

49

I faced the same issue with Gson library and searched for the solution a lot but none of them work for me then I read the R8 full mode true changes and added this three-line in proguard and it worked fine for me.

if someone face the same issue, you can try this:

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type
Deluar Hossen
  • 595
  • 4
  • 6
  • 2
    This occurs in signed APK, if you have debug APK you probably wont get this error. I was wondering. why this happens. then your answer gave what I needed to know. – Pavan Kumar T S Oct 22 '22 at 06:31
  • Thank you!!! This saved me from the weird bug that only appears in the release build. – Nithin Nov 26 '22 at 20:04
  • It's no weird, It happens only on release build because minifyEnabled (Inside gradle file) which make the code obfuscated probably set to true on only on release build, – Jesus Dimrix Mar 16 '23 at 10:53
  • Which is why I now have minifyEnabled set to true on debug as well, I want to know about these elusive errors way before I try to release, not on the night we are trying to release. – LordWabbit May 21 '23 at 05:45
  • [Here](https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg) you have an example of a proguard for Android to be compatible with Gson. I had the same problem and solved it with this configuration. – francas May 24 '23 at 12:56
  • working.. idk why these bugs occur – midou Aug 08 '23 at 08:25
2

The class TypeToken requires a type parameter.

Looking at your code, it looks like you should replace

Type listType = new TypeToken() {
}.getType();

with

Type listType = new TypeToken<List<Face>>() {
}.getType();
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59