gpt4 book ai didi

android - 由 java.lang.RuntimeException : Missing type parameter 引起

转载 作者:行者123 更新时间:2023-12-04 23:52:03 29 4
gpt4 key购买 nike

我正在检索 json当我使用 gson 将其转换为列表时,应用程序崩溃。 proguard开启,问题就在那里。

fun getQuestions(): List<Question>? {
val json = getQuestionsJsonData()
return GsonBuilder().create().fromJson(
json,
object : TypeToken<List<Question>?>() {}.type
)
}
由于我混淆了我的代码,我无法看到 crash登录 logcat ,所以我把它发送到 firebase crashlitycs .错误消息是 - Caused by java.lang.RuntimeException: Missing type parameter.也许 Question输入 get 被混淆或发生类似的事情。
我的proguard文件:
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}

-keepclassmembers class **.R$* {
public static <fields>;
}

#Serialized
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

# Uncomment this to preserve the line number information for
# debugging stack traces.
-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
-renamesourcefileattribute SourceFile
也许我必须在 proguard 文件中添加一些东西?
附言问题仅在 Gradle 7.1.0

最佳答案

在我的情况下,只是将以下内容添加到 proguard 配置中:

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
这是 Gson 所需的全套选项 -> https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg

关于android - 由 java.lang.RuntimeException : Missing type parameter 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70969756/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com