gradle在哪里准备"apply plugin"?

red*_*rom 8 android google-analytics android-gradle-plugin

我正在尝试使用本教程在我的应用程序中添加Google分析:

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

但我坚持这个问题,在哪里准确地说:

apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

所以我的build.gradle顶级文件看起来像这样:

// 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()
    }
}
Run Code Online (Sandbox Code Playgroud)

但这是错误的.请问应该在哪里放置apply plugin?

谢谢你的帮助.

Gab*_*tti 6

在andriod studio中,您具有以下结构:

root
   build.gradle
   app
      build.gradle
Run Code Online (Sandbox Code Playgroud)

在顶层build.gradle中,您具有:

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()
    }
}
Run Code Online (Sandbox Code Playgroud)

在你的 app/build.gradle

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

 //...


dependencies{
   //.....
   compile 'com.google.android.gms:play-services-analytics:7.3.0'
}
Run Code Online (Sandbox Code Playgroud)