Using android.support.v7.widget.CardView in my project (Eclipse)

AndroidEclipseAndroid 5.0-LollipopAndroid Cardview

Android Problem Overview


I'd like to use the new CardView widget that was introduced with the new Android L Developer Preview Support Library (As mentioned here), which seems to be part of a new revision of the v7 support library.

I have now updated my SDK version, downloaded the newest Support Library package, but I still cannot find the new CardView widget.

I already searched the web and the official docs, but could not get any hints on where I can get the new support library.

Any help is highly appreciated!

EDIT: I'm using ADT/Eclipse

Android Solutions


Solution 1 - Android

Using Gradle or Android Studio, try adding a dependency on com.android.support:cardview-v7.

There does not seem to be a regular Android library project at this time for cardview-v7, leanback-v17, palette-v7, or recyclerview-v7. I have no idea if/when Google will ship such library projects.

Solution 2 - Android

I finally found a way to use CardView in ADT/Eclipse. It's actually pretty easy:

  1. Create a new project in Android Studio
  2. Add the CardView dependency as explained in the other answers to this question
  3. Open ADT and create a new library project with package name android.support.v7.cardview
  4. Delete all resources ADT auto-created
  5. Find the exploded-aar folder in Android Studio and copy the following files to these locations:
    • res/values/values.xml to the same location in your ADT project
    • classes.jar to libs/ in your ADT project
    • AndroidManifest.xml use it to replace the auto-generated manifest in ADT
  6. Add classes.jar to the build path and make sure it's exported
  7. Add a reference to the library project in the project you want to use CardView in. You can follow the steps provided under Adding libraries with resources here: https://developer.android.com/tools/support-library/setup.html

As an alternative to having to create a new Android Studio project in order to get the AAR's content, you could also simply find and unzip the AAR from the local maven repo. Just follow the steps provided by Andrew Chen below.

Please note the CardView library might not be available in source- and ADT-compatible-form because it's still only a preview and a WIP. As there might be bug fixes and improvements in following releases, it's important to keep the library up-to-date, which is easy using the Gradle dependency, but must be done manually when using the steps provided above.

Solution 3 - Android

You need to add this in your build.gradle:

dependencies {
    ...
    compile 'com.android.support:cardview-v7:+'
}

And then Sync Project with Gradle Files. Finally, you can use CardView as it's described here.

Solution 4 - Android

I have done following and it resolve an issue with recyclerview same you may use for other widget as well if it's not working in eclipse project.

• Go to sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1 directory

• Copy recyclerview-v7-21.0.0-rc1.aar file and rename it as .zip

• Unzip the file, you will get classes.jar (rename the jar file more meaningful name)

• Use the following jar in your project build path or lib directory.

and it resolve your error.

happy coding :)

Solution 5 - Android

https://github.com/yongjhih/CardView

A CardView v7 eclipse project. (from sdk/extras/android/m2repository/com/android/support/cardview-v7)

The project was built by steps:

cp {sdk}/extras/android/m2repository/com/android/support/cardview-v7/21.0.0-rc1/cardview-v7-21.0.0-rc1.aar cardview-v7-21.0.0-rc1.zip
unzip cardview-v7-21.0.0-rc1.zip
mkdir libs/
mv classes.jar libs/cardview-v7-21.0.0-rc1.jar

Solution 6 - Android

I was able to work it out only after adding those two TOGETHER:

dependencies {
...
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
...
}

in my build.gradle (Module:app) file

and then press the sync now button

Solution 7 - Android

Although a bit hidden it's in the official docs here where can the library be found among the sdk's code, and how to get it with resources (the Eclipse way)

Solution 8 - Android

From: https://developer.android.com/tools/support-library/setup.html#libs-with-res

Adding libraries with resources To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:

Using Eclipse

Create a library project based on the support library code:

  • Make sure you have downloaded the Android Support Library using the SDK Manager.

  • Create a library project and ensure the required JAR files are included in the project's build path:

  • Select File > Import.

  • Select Existing Android Code Into Workspace and click Next.

  • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to /extras/android/support/v7/appcompat/.

  • Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.

  • In the new library project, expand the libs/ folder, right-click each .jar file and select Build

  • Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.

  • Right-click the library project folder and select Build Path > Configure Build Path.

  • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.

  • Uncheck Android Dependencies.

  • Click OK to complete the changes.

  • You now have a library project for your selected Support Library that you can use with one or more application projects.

  • Add the library to your application project:

  • In the Project Explorer, right-click your project and select Properties.

  • In the category panel on the left side of the dialog, select Android.

  • In the Library pane, click the Add button.

  • Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.

  • In the properties window, click OK.

Solution 9 - Android

Maybe it's a little bit late to add answer here. But I think this answer will help the later ones and especially those who don't want to use Android Studio.

Although the documents says that RecyclerView and CardView are part of v7 appcompat library. But as I tried and found, RecyclerView and CardView are actually depend on v7 appcompat library. So if you want to use RecyclerView or CardView, you need to add both v7 appcompat library and RecyclerView/CardView.

Referencing the link here, if you want to use CardView in your Eclipse android project, you need to import both v7 appcompat library and CardView into Eclipse workspace and make them as library projects. Then make CardView project depends on v7 appcompat library project and make your project depends on CardView project.

Solution 10 - Android

Simply add the following line in your build.gradle project

dependencies {
    ...
    compile 'com.android.support:cardview-v7:24.0.0'
}

And sync the project with gradle.

Solution 11 - Android

I did what FD_ said and it crashed with errors as it was looking for "Landroid/support/v7/cardview/R$styleable;", which was not compiled with it

If you really want to use CardView before in eclipse before it gets its own library, you can extract the classes from the classes.jar, copy and paste them into your project, with the values.xml from above from Android Studio and change all the references to android.support.v7.R to yourpackagename.R in the copied classes. This worked and ran for me

Solution 12 - Android

In the most latest android, we implement card view like this:

build.gradle file:

dependencies {
    ...
    compile 'com.android.support:cardview-v7:24.0.0'
}

and in the xml file its referenced as:

<androidx.cardview.widget.CardView
…></androidx.cardview.widget.CardView>

this means its class has changed to: androidx.cardview.widget.CardView

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
QuestionFD_View Question on Stackoverflow
Solution 1 - AndroidCommonsWareView Answer on Stackoverflow
Solution 2 - AndroidFD_View Answer on Stackoverflow
Solution 3 - AndroidadbocoView Answer on Stackoverflow
Solution 4 - AndroidRajat SharmaView Answer on Stackoverflow
Solution 5 - AndroidAndrew ChenView Answer on Stackoverflow
Solution 6 - AndroidRoy DoronView Answer on Stackoverflow
Solution 7 - AndroidEloi NavarroView Answer on Stackoverflow
Solution 8 - AndroidI'm_With_StupidView Answer on Stackoverflow
Solution 9 - AndroidMichelleView Answer on Stackoverflow
Solution 10 - AndroidPihuView Answer on Stackoverflow
Solution 11 - AndroidKieronView Answer on Stackoverflow
Solution 12 - Androiduser3044482View Answer on Stackoverflow