No resource identifier found for attribute 'layout_behavior' in package

user3421416 picture user3421416 · Sep 29, 2015 · Viewed 97.2k times · Source

My application worked fine until I tried to add a library to it. After I added the library, Android Studio gives me the following error:

Error:(26) No resource identifier found for attribute 'layout_behavior' in package 'inf..'

This is my build.gradle file:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.ogaclejapan.smarttablayout:utils-v4:1.3.0@aar'
    compile 'com.ogaclejapan.smarttablayout:library:1.3.0@aar'
    compile 'com.jpardogo.materialtabstrip:library:1.1.0'
    // compile 'com.lorentzos.swipecards:library:1.0.9@aar'
    compile 'com.android.support:cardview-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile project(':swipelib')
}

This is the xml which causes the error:

 <android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

I tried the following:

  • Removed the library
  • Reset Android Studio and my computer
  • Reverted to previous version of my code from git.

However, the error persists. How do I resolve this?

Answer

kris larson picture kris larson · Sep 29, 2015

That string resource is defined within the Material Design support library.

Since you're not using the CoordinatorLayout from the Material Design support library, you should be able to safely remove the app:layout_behavior attribute. It was probably cut & paste from other code.

NOTE: If you are actually using CoordinatorLayout and want the cooperative scrolling behaviors to work, you need to add the dependency for the latest version of the Material Design Support library to your Gradle build file:

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

UPDATE: Note that with the latest versions of Gradle the compile configuration has been deprecated in favor of implementation and api configurations so your dependency could look like this:

implementation 'com.android.support:design:27.0.2'

This is only an example; the version numbers may be out of date when you read this, so make sure your version matches the version of the support library that you want to use.

For more info: What's the difference between implementation and compile in gradle