Firstly, there are two types of gradle files.
build.gradle(Project: ProjectName)build.gradle(Module: app)
For more information about these two files, follow this answer .
Getting to your question
I found many answers on the net, but no one helped. I use Android Studio 2.1.2, my activity extends AppCompatActivity and is added to gradle (2 files), which I found relevant: but still an error appears.
From everything you posted, it seems like you haven't added the right things to the right places.
Cannot place application dependencies in build.gradle(Project: ProjectName) - Android Studio says
//NOTE. Do not post application dependencies here; they belong
// in a separate module build.gradle files
Hence, replace your dependencies in build.gradle(Project: ProjectName) below
dependencies { classpath 'com.android.tools.build:gradle:2.1.2' }
Replace your dependencies in build.gradle(Module: app) below
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:design:24.1.1' }
After execution, as indicated above, you will see the option "Sync now" in the upper right corner. Click on it. Android Studio will take care of other things.
Also this question is similar to yours. Go through it. This can help.
source share