Error while adding dependencies in Android Studio
When I want to add a new library to my build.gradle file it generates an error. this is my build.gradle file:
// 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:1.0.0'
compile 'com.mcxiaoke.volley:library:1.0.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and this is a mistake
C: \ Users \ Fakher \ Documents \ Play_Store_WS \ VolleyJson \ build.gradle Error: Error: line (10) Gradle DSL method not found: 'compile ()' Possible reasons:
The "VolleyJson" project may use a Gradle version that does not include this method. Gradle Settings The build file may be missing the Gradle plugin. Apply the Gradle Plugin
It doesn't work because you are putting the dependency in the wrong place, there are no plugins in this build.gradle to handle your dependency, you must add your dependency to the build.gradle which is inside your app module.
better to explain:
Your project has a folder called app , that is, your app module should have a build.gradle inside it, this build.gradle should have something like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
// bla bla bla
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//put your dependencies here
}
Hope I can help you.
You need to use build.gradle of your module instead of your project.
Look at this:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Go to build.gradle in your "App" module and then put:
compile 'com.mcxiaoke.volley:library:1.0.+'
you have to add your dependencies in buil.gradle
under application / not build.gradle
in your project