使用AppCompat'layout_behavior'和'@ string / appbar_scrolling_view_behavior'会引发exception

我有一个奇怪的探针使用AppCompat Lib 22.2与新的介绍:layout_behavior

如果我使用它的值“@ string / appbar_scrolling_view_behavior”,如这里所描述的Androiddevise支持库应用程序终止,以下例外:

Could not inflate Behavior subclass android.support.design.widget.Settings Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.Settings Caused by: java.lang.ClassNotFoundException: android.support.design.widget.Settings Caused by: java.lang.NoClassDefFoundError: android/support/design/widget/Settings Caused by: java.lang.ClassNotFoundException: android.support.design.widget.Settings 

如果我改为:

 app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" 

一切正常。

我错过了什么?

Solutions Collecting From Web of "使用AppCompat'layout_behavior'和'@ string / appbar_scrolling_view_behavior'会引发exception"

对于遇到此exception并使用proguard的其他人,您需要添加以下proguard规则:

 -keep class android.support.design.widget.** { *; } -keep interface android.support.design.widget.** { *; } -dontwarn android.support.design.** 

或者如果您不想保留所有可用的devise库组件:

 -keepattributes *Annotation* -keep public class * extends android.support.design.widget.CoordinatorLayout.Behavior { *; } -keep public class * extends android.support.design.widget.ViewOffsetBehavior { *; } 

造成这种情况的另一个原因是当你扩展FloatingActionButton.Behavior并且没有(Context,AttributeSet)构造函数时。 devise库v。23.0.1发生在我身上

只要将这个构造函数添加到你的子类中:

 public FloatingActionButtonBehaviorSubclass(Context context, AttributeSet attrs) { super(); } 

您应该为您的项目添加devise库。

 compile 'com.android.support:design:22.2.0' 

检查示例https://github.com/chrisbanes/cheesesquare

对于仅在使用proguard时才使用此错误的开发人员,只需将一行添加到proguard规则文件即可:

 -keep public class * extends android.support.design.widget.CoordinatorLayout$Behavior { *; }