【发布时间】:2020-11-23 18:26:39
【问题描述】:
我创建了一个 gson 扩展来序列化和反序列化对象,如下代码。
/**
* To serialize the object to json string
*/
fun Any.toGson(): String {
return Gson().toJson(this)
}
/**
* To deserialize the json string to object of type <T>
*/
fun <T>String.toObject() : T{
return Gson().fromJson(this, object : TypeToken<T>() {}.type)
}
当我在发布模式下构建项目时,应用程序由于 proguard 规则而崩溃。
我添加了 proguard 规则 -keepattribute 签名。应用程序仍然崩溃。
2020-11-24 08:47:28.448 8215-8215/? E/Paramthrowable Stacktrace 错误:Throwable java.lang.AssertionError:非法类型变量引用 在 libcore.reflect.TypeVariableImpl.resolve(TypeVariableImpl.java:111) 在 libcore.reflect.TypeVariableImpl.getGenericDeclaration(TypeVariableImpl.java:125) 在 libcore.reflect.TypeVariableImpl.hashCode(TypeVariableImpl.java:47) 在 b.c.a.v.a.(TypeToken.java:9) 在 b.a.a.a.e.a.(ListExtension.kt:1) 在 o.u.u.f(ViewGroupUtilsApi14.java:11)
以上是堆栈跟踪。 ListExtension 包含问题中提到的代码 需要帮助来解决此问题。
【问题讨论】:
-
发生了什么崩溃?请添加日志。
标签: android kotlin gson proguard kotlin-extension