Unsupported Gradle Dsl Method Found: 'compile()'!
Solution 1:
The Google documentation you quoted is correct, and doesn't conflict. There's more than one build.gradle file. Instead of putting dependencies in the top-level one as you have, put them in the build file that's in your module's directory.
Also, don't put an apply plugin: 'android'
statement in that top-level build file; it will cause an error.
You can also add dependencies through the Project Structure UI, which does the right thing.
Solution 2:
Do not add dependencies in your project by editing its most 'external' build.gradle (YourProject/build.gradle). Edit the one that is under the 'app' module instead (YourProject/app/build.gradle).
There, by the way, you will find the declaration of one dependency, such as:
dependencies {
compilefileTree(dir: 'libs', include: ['*.jar'])
}
This block will be just below android { ... } configuration block. In my case, I am just adding leeloo dependencies, so it became:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile'net.smartam.leeloo:oauth2-client:0.1'compile'net.smartam.leeloo:oauth2-common:0.1'
}
Then sync your project and dependencies will be downloaded. Hope it helps!
Solution 3:
the compile-time dependencies should reside in the dependencies
block under allprojects
, not under buildscript
:
apply plugin: 'android'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
jcenter()
}
dependencies {
compile'com.google.android.gms:play-services:18'
}
}
This should work fine.
Solution 4:
Think of “Gradle DSL method” as a Java method. So in Gradle, methods can be distinguished by either {} or “.”. So
dependencies {
compilefileTree(dir: 'libs', include: ['*.jar'])
}
is the same as
dependencies.compilefileTree(dir: 'libs', include: ['*.jar'])
where both “dependencies” and “compile” are methods.
So you are including a method somewhere in your build.gradle file that is not supported by your program. For example, make your dependencies this:
dependencies {
nothing 'this.does.nothing.build:gradle:0.7.+'
}
Which is the same as writing:
dependencies.nothing'this.does.nothing.build:gradle:0.7.+'
And you will see an error saying “unsupported Gradle DSL method found: ‘nothing()’!” Obviously "nothing" is not a real method. I just made it up.
So one of your "compile" methods inside your build.gradle is wrong.
Solution 5:
I am not sure why a down vote is given to previously mentioned solutions(Scott Barta & JBaruch). If we go through solution and comments mentioned above, it works completely.
However, when I faced this problem I used android developer UI to import dependencies as follows:-
1 Go to View ---> Open Module Settings
- Select Dependency tab. Click + to add a dependency and select Library dependency. Choose the downloaded library here.
Post a Comment for "Unsupported Gradle Dsl Method Found: 'compile()'!"