According to the manual https://developer.android.com/training/material/lists-cards.html?hl=en

For the material cards to work, you must install the dependency in build.gradle. After adding dependencies, this file began to look like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' compile 'com.android.support:cardview-v7:23.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } 

However, when compiled, it gives an error

 Could not find method compile() for arguments [com.android.support:cardview-v7:23.3.0] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@6169f20c. 

How to solve this problem?

    2 answers 2

    You need to place this dependency in the module's build.gradle file, not the entire application. It is not in the project root, but in the app / folder (or as your module is called)

    scrn

      In the comments in the file you have clearly stated

        // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files 

      those. You did not place your dependency in the gradle module file, but in the project file.

      You need to place the dependency in the module file.