33

I am trying to use card_view. But it keeps giving an error.

Error:(13) No resource identifier found for attribute `'cardCornerRadius' in package 'com.google.example.test_app'

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:background="#610B0B"
    tools:context=".MyActivity"
    android:id="@+id/myactivity ">
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:background="#fff"
        card_view:cardCornerRadius="4dp">
        <TextView
        android:id="@+id/my_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next"
        android:background="#fff"
        android:elevation="5dp" />
    </android.support.v7.widget.CardView>
</RelativeLayout>

What am I doing wrong here?

bubakazouba
  • 1,633
  • 2
  • 22
  • 34
Jelleroggie
  • 365
  • 1
  • 4
  • 7

5 Answers5

21

EDIT: This has been fixed in the Android 5.0 Lollipop SDK. Simply add

compile 'com.android.support:cardview-v7:21.+'

to your build.gradle and you're good to go.

OLD answer:

You'll need to add the cardview support library dependency to build.gradle:

compile 'com.android.support:cardview-v7:21.+'

However, due to the way Google built the library, you'll also have to compile your app using the latest "L" SDK:

compileSdkVersion "android-L"
buildToolsVersion "20.0.0"

and

minSdkVersion 14
targetSdkVersion "L"

Note that the minSdkVersion here doesn't really matter - as long as you compile with "L" SDK, your app can only run on L device/emulator no matter what minSdkVersion is specified.

The only viable way to build with the cardview lib for earlier Android version seems to be using Eddie Ringle's workaround.

See Failure [INSTALL_FAILED_OLDER_SDK] Android-L for some related info.

Community
  • 1
  • 1
mindex
  • 1,606
  • 13
  • 18
  • Hi mindex, are you saying that basically for the time being we cannot use the CardView for "real" implementations? Thanks – Lisa Anne Sep 24 '14 at 15:27
  • 1
    @LisaAnne you may want to check out http://toastdroid.com/2014/09/03/unlocking-recyclerview/ – mindex Oct 11 '14 at 09:51
  • It fixed the issue completely! But try to avoiding Cardview/Recyclerview jars if you are on Studio. In eclipse you still need jars. Thanks! – sud007 Feb 06 '15 at 20:03
17

For eclipse We need to include both the things add android.support.v7.widget.CardView as a library project and also add + check it's jar file in java build path

  • Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish
  • Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok
  • Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok
  • Right click on your project again --> build path --> configure build path -->under libraries-->add jar-->expand cardview-->expand libs-->select android.support.v7.widget.CardView.jar

under order and export-->check android.support.v7.widget.CardView.jar-->click

Hope it will help someone.

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
Akanksha Rathore
  • 3,603
  • 3
  • 31
  • 47
13

Please add this line compile 'com.android.support:cardview-v7:23.1.1' in build.gradle file under dependencies.

Please visit this link for the latest changes has made for any dependencies.

Anilkumar
  • 171
  • 2
  • 5
3

I just resolved this problem by checking CardView project "Library Module" in Android Studio.

Wendy Chen
  • 161
  • 1
  • 1
  • 8
2

For those of you coming in here looking for Xamarin-specific, once you've added the Android Support Library v7 CardView component, you need to Clean your project and then re-build.

brazilianldsjaguar
  • 1,409
  • 1
  • 20
  • 45