John61590
John61590

Reputation: 1106

Trouble getting Android Support V7 CardView Library to work

I'm using IntelliJ/Android Studio with Ant build (not Gradle at the moment), and am trying to use android-support-v7-cardview.jar but I continue to get

android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.widget.CardView
java.lang.NoClassDefFoundError: android.support.v7.cardview.R$styleable

I am not using m2repository with the aar file, but am using the cardview at location

sdk/extras/android/support/v7

I have gotten it to work by using the classes from the jar in my own project, but it requires API 21 (5.0) which I don't want to use yet. I am trying to use the jar file in the libs folder and res files from

 sdk/extras/android/support/v7/cardview/res 

I have added the lib file and res files to my own project, but still get the error messages above. What should I do?

Upvotes: 7

Views: 7542

Answers (5)

Sakamiai
Sakamiai

Reputation: 405

I had the exact same problem after adding compile 'com.android.support:cardview-v7:23.2.1' to build.gradle's dependencies to use the CardView, however after cleaning the project (Build > Clean Project) everything worked like magic.

Upvotes: 14

Kalpesh
Kalpesh

Reputation: 1807

If you are using Android Studio then its quick easier, Please add compile 'com.android.support:cardview-v7:21.+' in dependencies in build.gradle.

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

Upvotes: 0

SureshCS50
SureshCS50

Reputation: 3768

Hi this might be helpful, this worked for me. (for intellij users)

  • click in your project,
  • right click -> open Module Settings (f4)
  • import cardview from \sdk\extras\android\support\v7\
  • add .jar file to cardview module
  • click on your project and give module dependency to cardview
  • now, click (+) button on cardview -> android -> at top you will see a check box (library module), enable it.
  • click ok and close your settings dialog.
  • rebuild your project and run it.

Upvotes: 2

John61590
John61590

Reputation: 1106

I didn't figure out the error really but I just commented out the stuff that uses Android 5.0 in the source code of the library and it works fine. I didn't want to use a minSdk of Android 5.0.

Upvotes: 0

Simon
Simon

Reputation: 13283

I think you have to import it as an Android library project, then the ressources should be found correctly. I also tried first to import only the jar which didn't work, so I did it this way:

  1. The project for the CardView is located in your Android SDK folder: Android\android-sdk\extras\android\support\v7\cardview
  2. In Eclipse use "Import" and select "Existing Android Code Into Workspace" and import the CardView project
  3. Go to Properties->Android of the new project, mark it as a library project and then Link it as a library project in your own project where the CardView can not be found

That should do it

Upvotes: 0

Related Questions