启用 Proguard 时 Gson 会导致枚举字段崩溃
Gson Crashing Enum Fields When Enabling Proguard
就我而言
启用 Proguard 时 Proguard Gson 在枚举字段崩溃。
我的整个代码都在 kotlin 中。我通过将枚举保留在如下混淆器规则中得到了解决方案。
-keepclassmembers enum * {
public *;
}
But I want to apply proguard to enum then How Can I do that? Below is my code.
data class Notification(
@SerializedName("createdate")
val createdate: String = "",
@SerializedName("lastupdate")
val lastupdate: String? = null,
@SerializedName("member_id")
val memberId: Int = 0,
@SerializedName("notification_source")
val notificationSource: PushType,
): Serializable
enum class
enum class PushType {
Calendar,
Reminder,
Friend,
Timeline,
Savings,
Email,
MemoryBox,
InstantMessage;
}
I also tried with below Enum
enum class PushType {
@SerializedName("Calendar")
Calendar,
@SerializedName("Reminder")
Reminder,
@SerializedName("Friend")
Friend,
@SerializedName("Timeline")
Timeline,
@SerializedName("Savings")
Savings,
@SerializedName("Email")
Email,
@SerializedName("MemoryBox")
MemoryBox,
@SerializedName("InstantMessage")
InstantMessage;
}
I have tried below 2 solution
-
-
After trying above solution crash issue fix but again when I trying to
get detail it's giving me below error.
java.lang.NullPointerException: 尝试在空对象引用
上调用虚拟方法'int java.lang.Enum.ordinal()'
将 "notification_source" 的数据类型更改为字符串并像这样使用枚举
@StringDef(Calendar, Reminder, Friend, Timeline, Savings, Email, MemoryBox, InstantMessage)
@Retention(AnnotationRetention.SOURCE)
annotation class PushType {
companion object {
const val Calendar = "Calendar"
const val Reminder = "Reminder"
const val Friend = "Friend"
const val Timeline = "Timeline"
const val Savings = "Savings"
const val Email = "Email"
const val MemoryBox = "MemoryBox"
const val InstantMessage = "InstantMessage"
}
}
就我而言
启用 Proguard 时 Proguard Gson 在枚举字段崩溃。
我的整个代码都在 kotlin 中。我通过将枚举保留在如下混淆器规则中得到了解决方案。
-keepclassmembers enum * {
public *;
}
But I want to apply proguard to enum then How Can I do that? Below is my code.
data class Notification(
@SerializedName("createdate")
val createdate: String = "",
@SerializedName("lastupdate")
val lastupdate: String? = null,
@SerializedName("member_id")
val memberId: Int = 0,
@SerializedName("notification_source")
val notificationSource: PushType,
): Serializable
enum class
enum class PushType {
Calendar,
Reminder,
Friend,
Timeline,
Savings,
Email,
MemoryBox,
InstantMessage;
}
I also tried with below Enum
enum class PushType {
@SerializedName("Calendar")
Calendar,
@SerializedName("Reminder")
Reminder,
@SerializedName("Friend")
Friend,
@SerializedName("Timeline")
Timeline,
@SerializedName("Savings")
Savings,
@SerializedName("Email")
Email,
@SerializedName("MemoryBox")
MemoryBox,
@SerializedName("InstantMessage")
InstantMessage;
}
I have tried below 2 solution
After trying above solution crash issue fix but again when I trying to get detail it's giving me below error.
java.lang.NullPointerException: 尝试在空对象引用
上调用虚拟方法'int java.lang.Enum.ordinal()'将 "notification_source" 的数据类型更改为字符串并像这样使用枚举
@StringDef(Calendar, Reminder, Friend, Timeline, Savings, Email, MemoryBox, InstantMessage)
@Retention(AnnotationRetention.SOURCE)
annotation class PushType {
companion object {
const val Calendar = "Calendar"
const val Reminder = "Reminder"
const val Friend = "Friend"
const val Timeline = "Timeline"
const val Savings = "Savings"
const val Email = "Email"
const val MemoryBox = "MemoryBox"
const val InstantMessage = "InstantMessage"
}
}