Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreferenceFragmentCompat crashes on initalization

I have made an application with a ViewPager. Everything is working fine, when I make a debug build, and test it on my phone. (Not emulator) But when I build a release .apk and install it, the PreferenceFragmentCompat's addPreferencesFromResource(R.xml.preferences); crashes the app. PreferenceFragmentCompat - Android Developers

ApplicationSettingsFragment.java:

package hu.t_bond.homecontroller.Fragments;

import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;

import hu.t_bond.homecontroller.Launcher;
import hu.t_bond.homecontroller.R;

public class ApplicationSettingsFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        getPreferenceManager().setSharedPreferencesName(Launcher.SETTINGS_NAME);

        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public void onCreatePreferences(Bundle bundle, String s)
    {
    }
}

res/xml/preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <CheckBoxPreference
        android:key="AutoUpdatesEnabled"
        android:title="@string/auto_updates_enabled"
        android:summary="@string/auto_updates_enabled_description"
        android:defaultValue="true" />
</PreferenceScreen>

And the crash report:

10-26 14:20:07.661 17763-17890/? E/AndroidRuntime: FATAL EXCEPTION: main
 Process: hu.t_bond.homecontroller, PID: 17763
 android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
     at android.support.v7.preference.p.a(PreferenceInflater.java:261)
     at android.support.v7.preference.p.a(PreferenceInflater.java:280)
     at android.support.v7.preference.p.b(PreferenceInflater.java:289)
     at android.support.v7.preference.p.a(PreferenceInflater.java:161)
     at android.support.v7.preference.p.a(PreferenceInflater.java:117)
     at android.support.v7.preference.q.a(PreferenceManager.java:115)
     at android.support.v7.preference.j.b(PreferenceFragmentCompat.java:366)
     at hu.t_bond.homecontroller.b.a.d(ApplicationSettingsFragment.java:18)
     at android.support.v4.b.o.h(Fragment.java:1942)
     at android.support.v4.b.ac.a(FragmentManager.java:1040)
     at android.support.v4.b.ac.b(FragmentManager.java:926)
     at android.support.v4.b.o.c(Fragment.java:882)
     at android.support.v4.b.an.b(FragmentStatePagerAdapter.java:152)
     at android.support.v4.view.ViewPager.a(ViewPager.java:1104)
     at android.support.v4.view.ViewPager.a(ViewPager.java:552)
     at android.support.v4.view.ViewPager.a(ViewPager.java:514)
     at android.support.v4.view.ViewPager.b(ViewPager.java:946)
     at android.support.v4.view.dw.onChanged(ViewPager.java:2910)
     at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
     at android.support.v4.view.bo.c(PagerAdapter.java:276)
     at hu.t_bond.homecontroller.w.c(Launcher.java:948)
     at hu.t_bond.homecontroller.Launcher.a(Launcher.java:521)
     at hu.t_bond.homecontroller.q.onClick(Launcher.java:663)
     at android.view.View.performClick(View.java:4789)
     at android.view.View$PerformClick.run(View.java:19881)
     at android.os.Handler.handleCallback(Handler.java:739)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:135)
     at android.app.ActivityThread.main(ActivityThread.java:5292)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
  Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
     at java.lang.Class.getConstructor(Class.java:531)
     at java.lang.Class.getConstructor(Class.java:495)
     at android.support.v7.preference.p.a(PreferenceInflater.java:248)
     at android.support.v7.preference.p.a(PreferenceInflater.java:280) 
     at android.support.v7.preference.p.b(PreferenceInflater.java:289) 
     at android.support.v7.preference.p.a(PreferenceInflater.java:161) 
     at android.support.v7.preference.p.a(PreferenceInflater.java:117) 
     at android.support.v7.preference.q.a(PreferenceManager.java:115) 
     at android.support.v7.preference.j.b(PreferenceFragmentCompat.java:366) 
     at hu.t_bond.homecontroller.b.a.d(ApplicationSettingsFragment.java:18) 
     at android.support.v4.b.o.h(Fragment.java:1942) 
     at android.support.v4.b.ac.a(FragmentManager.java:1040) 
     at android.support.v4.b.ac.b(FragmentManager.java:926) 
     at android.support.v4.b.o.c(Fragment.java:882) 
     at android.support.v4.b.an.b(FragmentStatePagerAdapter.java:152) 
     at android.support.v4.view.ViewPager.a(ViewPager.java:1104) 
     at android.support.v4.view.ViewPager.a(ViewPager.java:552) 
     at android.support.v4.view.ViewPager.a(ViewPager.java:514) 
     at android.support.v4.view.ViewPager.b(ViewPager.java:946) 
     at android.support.v4.view.dw.onChanged(ViewPager.java:2910) 
     at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37) 
     at android.support.v4.view.bo.c(PagerAdapter.java:276) 
     at hu.t_bond.homecontroller.w.c(Launcher.java:948) 
     at hu.t_bond.homecontroller.Launcher.a(Launcher.java:521) 
     at hu.t_bond.homecontroller.q.onClick(Launcher.java:663) 
     at android.view.View.performClick(View.java:4789) 
     at android.view.View$PerformClick.run(View.java:19881) 
     at android.os.Handler.handleCallback(Handler.java:739) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5292) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 

And I'm using the newest libs:

compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:preference-v7:23.1.0'

Can somebody tell me what I'm doing wrong? Thanks

like image 968
T-bond Avatar asked Oct 26 '15 13:10

T-bond


Video Answer


1 Answers

The OP said he is using ProGuard when building his APK file.

As this bug report states

Make sure your proguard configuration contains a line like this:

-keep public class * extends android.support.v7.preference.Preference

This might be the issue, although I'm not sure.

like image 167
Marko Avatar answered Sep 30 '22 16:09

Marko