android – gradle究竟要放“apply plugin”?

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

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

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

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

所以我的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()
    }
}

但这是错误的.请问应该在哪里申请插件

谢谢你的帮助.

解决方法

在andriod工作室你有这种结构:
root
   build.gradle
   app
      build.gradle

在顶级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()
    }
}

在你的app / build.gradle中

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

 //...


dependencies{
   //.....
   compile 'com.google.android.gms:play-services-analytics:7.3.0'
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...