Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle where exactly to put "apply plugin"?

i'm trying to add Google analytics inside of the my app using this tutorial:

https://developers.google.com/analytics/devguides/collection/android/v4/

But i stucked on the problem, where to exactly put the line:

apply plugin: 'com.google.gms.google-services'

So my build.gradle top level file is looking like this:

// 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.3.0'
        classpath 'com.google.gms:google-services:1.3.0-beta1'
        apply plugin: 'com.google.gms.google-services'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

But this is wrong. Where to put apply plugin exactly please?

Thanks for any help.

like image 833
redrom Avatar asked Aug 26 '15 08:08

redrom


People also ask

Where do I put plugins in build Gradle?

Put the source of the plugin directly into the build. gradle file. One big advantage of this approach is that the class is automatically compiled and added to the classpath of the build script without you configuring anything. The disadvantage is that the plugin cannot be used in another module.

How does apply plugin work in Gradle?

Applying a plugin to a project allows the plugin to extend the project's capabilities. It can do things such as: Extend the Gradle model (e.g. add new DSL elements that can be configured) Configure the project according to conventions (e.g. add new tasks or configure sensible defaults)

Where is the application Gradle file?

The app level build. gradle file is located inside your project folder under app/build. gradle.


1 Answers

In andriod studio you have this kind of structure:

root
   build.gradle
   app
      build.gradle

In the top-level build.gradle you have:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.google.gms:google-services:1.3.0-beta1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

In your app/build.gradle

apply plugin: 'com.google.gms.google-services'

 //...


dependencies{
   //.....
   compile 'com.google.android.gms:play-services-analytics:7.3.0'
}
like image 109
Gabriele Mariotti Avatar answered Sep 19 '22 19:09

Gabriele Mariotti