Java – How to use appcompat-v7 with android API 19

How to use appcompat-v7 with android API 19… here is a solution to the problem.

How to use appcompat-v7 with android API 19

Everything is in the problem

I have a module with this gradle :

apply plugin: 'com.android.library'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    compileOptions.encoding "ISO-8859-1"

defaultConfig {
        minSdkVersion 8
        targetSdkVersion 8
    }

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
}

When I change “compileSdkVersion” to 19=> I get more than 100 errors about resource not found:

Example:

    Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body1'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body2'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Button'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Caption'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display1'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display2'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display3'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display4'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Headline'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Menu'.
Error:Error retrieving parent for item: No resource found that matches the given name '@android:TextAppearance.Material.SearchResult.Subtitle'.
Error:Error retrieving parent for item: No resource found that matches the given name '@android:TextAppearance.Material.SearchResult.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Subhead'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Title'.

Solution

Of course you will encounter these errors in API < 21 because android:TextAppearance.Material and others were introduced in API 21. AppCompat is porting resources, but they don’t use the android: prefix (I can’t check if you’re using these prefixes at the moment, but it could be). If you compile your application with API 21 and run it on a lower API, device crashes can also occur

The android: prefix refers to built-in parameters, which should be in all versions of supported APIs (minSDK). Material does not exist in pre-API 21 systems

Related Problems and Solutions