Search code examples
androidandroid-gradle-pluginbuild.gradleflurryflurry-analytics

Integrating Flurry on Android Studio: Gradle DSL Method not found - 'compile()'


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 file
  • The 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()
        }
    }
    

    Solution

  • 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
    }