我已经创建了一个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)
} 当我在发布模式下构建项目时,由于前卫规则,应用程序崩溃。
我已经添加了防护规则-keepattribute签名。尽管如此,这款应用还是在崩溃。
2020-11-24 08:47:28.448 8215-8215/?E/可参数堆栈跟踪错误:可抛出的堆栈跟踪:在libcore.reflect.TypeVariableImpl.resolve(TypeVariableImpl.java:111) at libcore.reflect.TypeVariableImpl.getGenericDeclaration(TypeVariableImpl.java:125) at libcore.reflect.TypeVariableImpl.hashCode(TypeVariableImpl.java:47) at b.c.a.v.a.(TypeToken.java:9) at b.a.e.a.(ListExtension.kt:1) at o.u.u.f(ViewGroupUtilsApi14.java:11)的堆栈跟踪错误:可抛出的java.lang.AssertionError:非法类型变量引用
上面是堆栈跟踪。ListExtension包含问题中提到的代码,需要帮助来解决此问题。
发布于 2020-11-24 13:16:40
在你的pro-guard文件中试试这个
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
# Do not obfuscate classes with Injected Constructors
-keepclasseswithmembernames class * { @javax.inject.Inject <init>(...); }
# Do not obfuscate classes with Injected Fields
-keepclasseswithmembernames class * { @javax.inject.Inject <fields>; }
# Do not obfuscate classes with Injected Methods
-keepclasseswithmembernames class * { @javax.inject.Inject <methods>; }
-keep class **__Factory { *; }
-keep class **__MemberInjector { *; }
# Specifies that string constants that correspond to class names should be obfuscated as well.
-adaptclassstrings com.example.your_package_name.**发布于 2020-11-24 14:53:29
##---------------Begin: proguard configuration for Gson ----------
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
# -keep class mypersonalclass.data.model.** { *; }添加保留模型的规则,我认为您的扩展函数在模型类中
https://stackoverflow.com/questions/64974191
复制相似问题