Android BadParcelableException 仅适用于已签名的 apk [英] Android BadParcelableException only with signed apk

查看:33
本文介绍了Android BadParcelableException 仅适用于已签名的 apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I run my project from debug everything works fine. However when I run it with the signed apk I generated from Android Studio (using proguard), I get the following errors when using 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 上?在我的 proguard 配置文件中,我确实必须使用 dontwarn android.support.v4.** 来避免 proguard 错误.这是回来咬我吗?

Why does this exception happen only with my signed apk? In my proguard config file I did have to use dontwarn android.support.v4.** to avoid proguard errors. Is that coming back to bite me?

推荐答案

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

You need to protect CREATOR fields from proguard's obfuscation

将此行添加到您的 proguard 配置中:

add this lines to your proguard config:

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

这篇关于Android BadParcelableException 仅适用于已签名的 apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆