缺少 Android CardView 库的资源

Missing resources for Android CardView library

我在项目中使用 CardView,但在旧设备上出现错误:

 E  android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.widget.CardView
                        E      at android.view.LayoutInflater.createView(LayoutInflater.java:518)
                        E      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
                        E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
                        E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
                        E      at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
                        E      at android.view.LayoutInflater.inflate(LayoutInflater.java:320)

似乎类似于 this one

等关于 SO 的一些问题

我的问题是,这些问题的解决方案感觉很老套,这是可以理解的,因为去年 Lollipop 刚进入 public 预览时就给出了答案。从那以后情况有变化吗?我如何获得资源?

我尝试了一些方法,例如将 .aar 作为模块导入,但似乎没有任何效果。我遵循了关于如何添加支持库 (https://developer.android.com/tools/support-library/setup.html#libs-with-res) 的官方文档,但这没有用。同样根据 link - 添加库和不添加 Android Studio 资源库之间似乎没有任何区别?

我的应用程序 build.gradle 包含以下依赖项:

compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'

这里使用的是CardView布局

    <android.support.v7.widget.CardView
        xmlns:card="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:foreground="?android:attr/selectableItemBackground"
        card:cardCornerRadius="6dp"
        card:cardUseCompatPadding="true"
        tools:ignore="NewApi">

编辑:Samsung S2 2.3 上发现的问题 - API 19+ 工作正常

?android:attr/selectableItemBackground 与平台相关,使用不带 android: 前缀的它来引用 AppCompat 的属性。