Search code examples
androidandroid-studioandroid-gradle-pluginandroid-actionbar-compat

Build errors with action bar, support library


I get many compilation errors when trying to add an ActionBar to my app. Any help is much appreciated!

I recently moved my application development from Eclipse to Android Studio. I'm an absolute novice wrt Android Studio and gradle. I want to add an ActionBar to my app. I want to support devices running at least API level 9. Per the Android developer doc, I see that I've got to use the V7 appcompat library. My SDK manager indicates that both Android Support Repository rev 11 and Android Support Library rev 21.0.3 have been installed. I've also read that my project should use both support-v4 as well as appcompat-v7 - is that right? The gradle file for my app module contains this:

defaultConfig {
    applicationId "com.tomoreilly.solarisalpha"
    minSdkVersion 9
    targetSdkVersion 9
}
[...]
dependencies {
    compile project(':androidLVL')
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/acra-4.2.3.jar')
    compile files('libs/htmllexer.jar')
    compile "com.android.support:appcompat-v7:21.0.3"
    compile 'com.android.support:support-v4:13.0.0'   
}

Not sure what version numbers to use for the libraries. I specify appcompat-v7:21.0.3 because SDK manager indicates Android Support Library rev 21.0.3. But what about the version number for support-v4? I just got "13.0.0" from an example on the internet, because support-v4 doesn't seem to show in my SDK manager at all.

When I try to build my project I get many errors like these:

Error:(6, 21) No resource found that matches the given name: attr 'android:actionModeCopyDrawable'. Error:(5, 21) No resource found that matches the given name: attr 'android:actionModeCutDrawable'. Error:(7, 21) No resource found that matches the given name: attr 'android:actionModePasteDrawable'. Error:(8, 21) No resource found that matches the given name: attr 'android:actionModeSelectAllDrawable'. Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

Can someone see what I am missing or doing wrong? Thanks! Tom


Solution

  • appcompat-v7 automatically includes support-v4, so you can remove that line entirely.

    Also make sure your compileSdkVersion in your build.gradle is set to 21 as well as per this question