I'm following the instructions for integrating Flurry Analytics using the official tutorial
I run into the problem that has been widely reported:
Error:(4, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'My_Project' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Here's the gradle file for the FlurryAnalytics-5.5.0 module autogenerated by Studio:
configurations.create("default")
artifacts.add("default", file('FlurryAnalytics-5.5.0.jar'))
dependencies {
compile files('FlurryAnalytics-5.5.0.jar')
}
I'm aware that a common solution prescribed in such questions as this one is to avoid putting the 'dependencies' closure in the top level build file. However, I don't have any non-gradle dependencies in that file, as is shown below.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
The compile option is a part of the Android Gradle Plugin.
You need to apply that plugin to your module's build.gradle file if the module is an Android module.
apply plugin: 'com.android.application' // Android Gradle Pllugin
android {
// Your Android configuration
}
With Jar:
dependencies {
compile files('FlurryAnalytics-5.5.0.jar') // Your Jar
}
or Maven Dependency:
dependencies {
compile 'com.flurry.android:analytics:6.2.0' // Latest Jcenter release
}
Related
So I'm new to App Development, and I'm struggling with the Gradle Sync:
Blockquote Error:(10, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'MyApplication' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.3 and sync projectThe project 'MyApplication' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
That is the error message I get.
This is the code I am using
// 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.3.3'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
apply plugin: 'project-report'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Please help with a way to fix this,
thanks in advance
Regards
There are two build.gradle files in your Android Studio project. The one that you edited is in the project's root directory. That's not the file you should have put those lines in. The other build.gradle is in your module's directory (e.g., app/). Those four compile lines go in a dependencies closure in that build.gradle file.
This is even mentioned in the comment in the file:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
This sample project (from this book) uses some of those same dependencies. My top-level build.gradle file does not have the compile statements:
// 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.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Instead, they are in the app/build.gradle file:
apply plugin: 'com.android.application'
dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
}
}
I want to use Gson and Retrofit to interact with an API. According to the documentations, I add theses lines into the build.gradle of my project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral() //this line
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
compile 'com.google.code.gson:gson:2.7' //this line
compile 'com.squareup.retrofit:retrofit:1.9.0' //this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral() //and this line
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
but I have these errors :
Error:(10, 0) Gradle DSL method not found: 'compile()' Possible
causes:The project 'TempoEDF' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade
plugin to version 2.3.3 and sync projectThe project
'TempoEDF' may be using a version of Gradle that does not contain the
method. Open Gradle wrapper
fileThe build file may be missing a Gradle plugin. Apply Gradle plugin
So I used the Gradle plugin like my IDE wants to:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
apply plugin: 'gradle'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit:retrofit:1.9.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
but I have this error :
Error:(10, 0) Plugin with id 'gradle' not found. Open
File
What did I do wrong?
so according to the documentations i add theses lines into the build.gradle of my project
Please note the comments in that file:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
I do not know what "documentations" that you read that told you to put these things in the project-level build.gradle file. Please consider providing links, so that we can get that material fixed.
To get past this problem, remove the changes that you made to this file. Then, add those dependencies to the module's build.gradle file (e.g., app/build.gradle in a typical Android Studio project).
For databinding
1) I have added
android {
dataBinding {
enabled = true
}
to my project build.gradle, but this error occurs:
Error:(5, 0) Gradle DSL method not found: 'dataBinding()'
Possible causes:
.The project 'exampleDatabinding' may be using a version of Gradle that does
not contain the method.
Gradle settings
.The build file may be missing a Gradle plugin.
Apply Gradle plugin
2) Then I added:
apply plugin: "com.android.databinding" (to project build.gradle)
and classpath "com.android.databinding:dataBinder:1.0-rc1" (to project build.gradle)
But the same error occured.
In the file build.gradle of the project add the dependency
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
And in the file build.gradle of the module include the dataBinding section:
android{
...
dataBinding {
enabled = true
}
...
}
The versions of build.gradle can be found here: Versions
The project 'exampleDatabinding' may be using a version of Gradle that does
not contain the method.
You need to update your gradle to latest version 2.10
To update gradle do as follows
YourProject->gradle->wrapper->gradle-wrapper.properties
update the distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.
Also add dataBinding:
android{
...
dataBinding {
enabled = true
}
...
}
Also update your classpath:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
I'm trying to add an external library. I've created in a/libs folder under project folder and have the following code in my gradle.build file. But it doesn't sync at all.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile 'com.radiusnetworks:AndroidIBeaconLibrary:0.7.1#aar'
}
The error I'm getting is:
Gradle 'BLE_Client' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'compile()'!
Possible causes could be:
- you are using Gradle version where the method is absent
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
You shouldn't add this dependency to the root-level build.gradle file. Add it to your module's build.gradle file instead. The top-level build file is for things that are common to all modules in your project, but it's highly unlikely that you'd want all modules to have the same dependencies, or even to share this one.
I have a build.gradle file in my library project, the content of it looks like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
.......
when I do gradle build, it gives error:
Could not find com.actionbarsherlock:actionbarsherlock:4.4.0.
If I change the line "apply plugin" from 'android-library' to 'android', it can compile fine.
So is it a bug with the gradle android plugin? that it cannot find actionbarsherlock correctly in maven repository if it's from a library project?
Make sure you select from Project Settings -> Gradle, "Use local gradle distribution" pointing to you local Gradle copy. Mine is 1.9 and I managed to make it work.