v7 support 23.0.1 crash: AppCompatButton.setBackgroundDrawable

故事扮演 提交于 2019-12-09 22:58:43

问题


I am experiencing this crash, with support library 23.0.1

It happens when showing a Dialog Fragment.

It verifies with both android.support.v4.app.DialogFragment and android.support.v7.app.AppCompatDialogFragment

Anyone else is experiencing this?

It always happens with release compilation (which has Proguard enabled), and only in some cases with debug compilation.

I am reporting the crash stacks for both fragment classes.

stack for android.support.v4.app.DialogFragment:

android.view.InflateException: Binary XML file line #115: Error inflating class Button
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
       at com.android.internal.app.AlertController.installContent(AlertController.java:235)
       at android.app.AlertDialog.onCreate(AlertDialog.java:356)
       at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
       at android.app.Dialog.show(Dialog.java:274)
       at android.support.v4.app.DialogFragment.onStart(SourceFile:406)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1060)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
       at android.support.v4.app.BackStackRecord.run(SourceFile:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
       at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
       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:5254)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.o.a()' on a null object reference
       at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(SourceFile:85)
       at android.view.View.setBackground(View.java:16226)
       at android.view.View.(View.java:4103)
       at android.widget.TextView.(TextView.java:637)
       at android.widget.Button.(Button.java:111)
       at android.widget.Button.(Button.java:107)
       at android.support.v7.widget.AppCompatButton.(SourceFile:64)
       at android.support.v7.widget.AppCompatButton.(SourceFile:60)
       at android.support.v7.internal.app.AppCompatViewInflater.createView(SourceFile:101)
       at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:966)
       at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
       at com.android.internal.app.AlertController.installContent(AlertController.java:235)
       at android.app.AlertDialog.onCreate(AlertDialog.java:356)
       at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
       at android.app.Dialog.show(Dialog.java:274)
       at android.support.v4.app.DialogFragment.onStart(SourceFile:406)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1060)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
       at android.support.v4.app.BackStackRecord.run(SourceFile:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
       at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
       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:5254)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

stack for android.support.v7.app.AppCompatDialogFragment:

android.view.InflateException: Binary XML file line #29: Error inflating class Button
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at eu.baroncelli.oraritrenitalia.mainactivity.AlertDialogFragment.onCreateView(SourceFile:62)
       at android.support.v4.app.Fragment.performCreateView(SourceFile:1962)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1026)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
       at android.support.v4.app.BackStackRecord.run(SourceFile:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
       at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
       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:5254)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.o.a()' on a null object reference
       at android.support.v7.widget.AppCompatButton.setBackgroundDrawable(SourceFile:85)
       at android.view.View.setBackground(View.java:16226)
       at android.view.View.(View.java:4103)
       at android.widget.TextView.(TextView.java:637)
       at android.widget.Button.(Button.java:111)
       at android.widget.Button.(Button.java:107)
       at android.support.v7.widget.AppCompatButton.(SourceFile:64)
       at android.support.v7.widget.AppCompatButton.(SourceFile:60)
       at android.support.v7.internal.app.AppCompatViewInflater.createView(SourceFile:101)
       at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:966)
       at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at eu.baroncelli.oraritrenitalia.mainactivity.AlertDialogFragment.onCreateView(SourceFile:62)
       at android.support.v4.app.Fragment.performCreateView(SourceFile:1962)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1026)
       at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1207)
       at android.support.v4.app.BackStackRecord.run(SourceFile:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1572)
       at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:493)
       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:5254)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

回答1:


According to this your proguard setup should contain the following rules if you're using appcompat-v7:

-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}

This will also save you from trouble when using SearchView and other things I imagine.



来源:https://stackoverflow.com/questions/32813894/v7-support-23-0-1-crash-appcompatbutton-setbackgrounddrawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!