Android BadParcelableException(Parcelable 协议(protocol)需要一个名为 CREATOR 的 Parcelable.Creator 对象)只有签名的 apk

标签 android android-studio proguard parcelable

当我从调试运行我的项目时,一切正常。但是,当我使用从 Android Studio(使用混淆器)生成的签名 apk 运行它时,在使用 getParcelable 时出现以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage.android/mypackage.mobile.android.activities.searchActivity}: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called  CREATOR on class mypackage.android.a.d.a

为什么这个异常只发生在我签名的 apk 上?在我的混淆器配置文件中,我必须使用 dontwarn android.support.v4.** 来避免混淆器错误。那是回来咬我吗?

最佳答案

您需要保护 CREATOR 字段免受 proguard 的混淆

将此行添加到您的混淆器配置中:

-keep class * implements android.os.Parcelable { 
   public static final android.os.Parcelable$Creator *; 
}

关于Android BadParcelableException(Parcelable 协议(protocol)需要一个名为 CREATOR 的 Parcelable.Creator 对象)只有签名的 apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19274974/

相关文章:

android - 从 Android 浏览器发出调用 Web 服务的问题

android - 通知 - 单击会触发错误的 PendingIntent

android - NDK 是减少逆向工程的替代方案吗?

Android Proguard 编译错误

java - 无法使用 proguard 保留方法

android - 为什么屏幕上的位置总是返回 0?

android - 更新查询的返回值为0

android-studio - Android Studio 显示错误的文件内容

android - 错误 "can' t 使用颠覆命令行客户端 : svn"when opening android project checked out from svn

android - 将 jar 作为库添加到 Android Studio,错误 : More than one file was found with OS independent path 'META-INF/DEPENDENCIES'