java.lang.AssertionError: illegal type variable reference
See original GitHub issuei use gson 2.8.5
in android project,run app with proguard on real Android Phone. when execute code Type listType = new TypeToken<List<T>>() {}.getType()
,then crash:
java.lang.AssertionError: illegal type variable reference
at libcore.reflect.TypeVariableImpl.resolve(TypeVariableImpl.java:111)
at libcore.reflect.TypeVariableImpl.getGenericDeclaration(TypeVariableImpl.java:125)
at libcore.reflect.TypeVariableImpl.hashCode(TypeVariableImpl.java:47)
at java.util.Arrays.hashCode(Arrays.java:4153)
at com.google.gson.internal.$Gson$Types$ParameterizedTypeImpl.hashCode($Gson$Types.java:502)
at com.google.gson.reflect.TypeToken.<init>(TypeToken.java:64)
......
i have add these code in proguard.pro
:
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes Deprecated
-keepattributes SourceFile
-keepattributes LineNumberTable
-keepattributes *Annotation*
-keepattributes EnclosingMethod
# Gson specific classes
-keep class sun.** { *; }
#-keep class com.google.gson.stream.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Gson illegal type variable reference - java - Stack Overflow
Inside this class there is a method doRequest that creates a TypeToken (from com.google.json.reflect ) for a Gson request. java.lang.reflect.
Read more >Gson:java.lang.AssertionError: illegal type variable reference
1、问题现象:APP使用XX加固助手加固之后,在安卓7.x.x 系统中会崩溃:错误信息为java.lang.AssertionError: illegal type variable reference。
Read more >Android:java.lang.AssertionError: illegal type variable reference
AssertionError : illegal type variable reference,1、问题现象:APP使用XX加固助手加固之后,在安卓7.x.x系统中会崩溃:错误信息为java.lang.
Read more >混淆导致的java.lang.AssertionError: illegal type ... - 程序员宅基地
在做混淆的时候,经常会出现各种奇怪的错误, 以下便是一种:java.lang.AssertionError: illegal type variable reference at libcore.reflect.
Read more >java.lang (Java SE 19 & JDK 19) - Oracle Help Center
The Void class is a non-instantiable class that holds a reference to a Class object representing the type void. The class Math provides...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lyubomyr-shaydariv maybe some other config cause this error. i config build.gradle
the problem solve. But when config
debuggable = ture
, the error occur T_T.@rosuH No need to have it such complex. You can simply create a method like this:
that will do the job. I’d only recommend this method if you provide the element types dynamically, not statically (also note that
gson
can be re-used, no need tonew
it). However, I believe you only need something like this:that would produce
[1, 2, 3, 4, 5, 6]
and[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
respectively. It is a little more verbose, but you don’t need to implement custom methods, and you can reuse type tokens too.