我的一些用户遇到了崩溃,这是 Google Play 开发者控制台上的崩溃报告中显示的错误:
Unable to start activity ComponentInfo{com.havens1515.autorespond/com.havens1515.autorespond.SettingsMenuNew}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.havens1515.autorespond.NotificationOptions: make sure class name exists, is public, and has an empty constructor that is public
用户表示,当打开其中的任何设置菜单时,就会发生这种情况SettingsMenuNew
上面的错误中提到了这一点,但我的手机上没有遇到崩溃。SettingsMenuNew
is a PreferenceActivity
所有子菜单都是PreferenceFragment
Each PreferenceFragment
有一个空的构造函数,我不知道还有什么问题。我还在别人的问题中看到它需要newInstance
方法,但如果我不将任何其他参数放入片段中,我认为我真的不需要它。
这是显示这些方法的一些代码:
public class NotificationOptions extends PreferenceFragment
{
public NotificationOptions()
{
}
public static NotificationOptions newInstance(int title, String message)
{
NotificationOptions f = new NotificationOptions();
return f;
}
...
}
这可能是由于 proguard 删除了您的片段而发生的。
要重现,请构建混淆的 APK,在开发人员选项中启用“不保留活动”,打开包含崩溃片段的活动。最小化主页按钮并从最近使用的应用程序恢复。
要将 proguard 配置与默认配置和您在 ADT 中的配置合并,您应该在 project.properties 中指定
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
如果您使用 Gradle 构建系统
buildTypes {
debug {
runProguard false
}
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
并且 proguard-project.txt 应该至少包含这些规则
-keep public class * extends android.preference.PreferenceFragment
如果您使用的是支持片段
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.support.v4.app.FragmentActivity
不要忘记 ${sdk.dir}/tools/proguard/proguard-android.txt 中已经包含了一些规则,因此根据您的需要仅添加缺少的规则。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)