attr/colorError not found error when using com.android.support:recyclerview-v7:26.0.0-beta2

AndroidGradleAndroid Recyclerview

Android Problem Overview


I'm using Android Studio 3.0 Canary 4. I imported the recycler view library. Then it comes out the attr/colorError not found message. This is app build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.robyn.myapplication"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:recyclerview-v7:26.0.0-beta2'
    implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
}

Whenever I add the two libraries implementation 'com.android.support:recyclerview-v7:26.0.0-beta2' and implementation 'com.android.support:appcompat-v7:26.0.0-beta2', it comes out this error message: enter image description here

I tried clean and rebuild, the error message is still there. I checked res/values/colors, the color values are there. Why I get this color error? If I want to use recycler view, what version of library should I import?

Android Solutions


Solution 1 - Android

Change the following details it will work fine,

compileSdkVersion 26
buildToolsVersion "26.0.0-beta2"
    

Solution 2 - Android

Also upgrading compileSDKVersion and buildToolsVersion to 26 (it was 25) fixed the issue for me:

compileSdkVersion 26
buildToolsVersion '26.0.2'
...
dependencies {
    ...
    compile 'com.android.support:appcompat-v7:26.0.2'

}

In general, make sure to keep all the versions consistent (compile, build, appcompat libraries).

This is to ensure compilation and stability on runtime (one can also see lint warning about the latter if lint finds differnet support library versions)

Solution 3 - Android

Revision 26.0.0 Beta 2

> Please note that 26.0.0-beta2 is a pre-release version. Its API > surface is subject to change, and it does not necessarily include > features or bug fixes from the latest stable versions of Support > Library.

For your problem you can use "26.0.0-beta2" . It will be better if you use Stable Version .

Solution 4 - Android

pasting following code at Android/build.gradle bottom helped me:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 28
                buildToolsVersion "28.0.3"
            }
        }
    }
}

Solution 5 - Android

I've seen the same error when my app is on appcompat-26 and tries to include an Android library which in turn uses appcompat-25. My solution has so far been to keep the app on 25 as well.

I have no idea if it's supposed to be like this. Surely you must be able to publish a library that uses the support lib version X and have it run in apps using support lib version X+1.

I am using AS 3.0-beta7 so maybe it's resolved on stable 3.0 which was released a few days ago.

Solution 6 - Android

Just change the minSdk:

e.g.:

android {
   compileSdkVersion 26
   buildToolsVersion "26.0.0-beta2"
   defaultConfig {
      applicationId "com.parse.starter"
      minSdkVersion 15
      targetSdkVersion 21
      versionCode 1
      versionName "1.0"
   }
}

Hope this helps

Solution 7 - Android

I found this "attr/colorError" error occurred when I had created product flavours and had put the "legacy" after the "current" in my build.gradle (in "app" folder). When I put the "legacy" before the "current" (as shown below) then the error went away. Maybe the lower "versionCode" or "Sdk" versions need to appear first?

   flavorDimensions "legacycurrent"
   productFlavors {

      legacy {
               dimension "legacycurrent"
               versionCode 98
               minSdkVersion 9
               targetSdkVersion 25
               compileSdkVersion 25
             }
      current {
               dimension "legacycurrent"
               versionCode 99
               minSdkVersion 14
               targetSdkVersion 26
               compileSdkVersion 26
             }
   }

Solution 8 - Android

FWW - For future searchers, I've added the code below to my root build.gradle to search down through dependencies and fix them to match my root project. There are probably caveats and reasons why this is a bad idea, but it consistently works for me.

subprojects {
    afterEvaluate {subproject ->
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

Solution 9 - Android

this code in android/build.gradle fixed my error.

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 31
                buildToolsVersion "30.0.2"
            }
        }
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobinView Question on Stackoverflow
Solution 1 - AndroidMuthukrishnan RajendranView Answer on Stackoverflow
Solution 2 - Androidvir usView Answer on Stackoverflow
Solution 3 - AndroidIntelliJ AmiyaView Answer on Stackoverflow
Solution 4 - AndroidAmit BravoView Answer on Stackoverflow
Solution 5 - AndroidJHHView Answer on Stackoverflow
Solution 6 - AndroidAhmed J.View Answer on Stackoverflow
Solution 7 - AndroidStephen BridgettView Answer on Stackoverflow
Solution 8 - AndroidDave WellingView Answer on Stackoverflow
Solution 9 - AndroidMuhammad NumanView Answer on Stackoverflow