如何将依赖项添加到项目的顶级build.gradle文件中? [英] How to add dependencies to project's top-level build.gradle file?

查看:446
本文介绍了如何将依赖项添加到项目的顶级build.gradle文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现 Google Cloud Messaging(GCM)的示例代码,该示例代码由Google本身提供,

解决方案

链接



将依赖项添加到项目的顶部级别 build.gradle :(只需编辑文件)

  classpath 'com.google.gms:google-services:1.3.0-beta1'

您应该有一些东西像这样:



//顶层构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

  buildscript {
存储库{
jcenter()
}
依赖项{
classpath'com.android.tools.build:gradle:1.3.0'
classpath'com.google.gms:google-services:1.3.0-beta1'

//注意:不要在此处放置应用程序依赖项;它们属于
// //在单个模块build.gradle文件
}
}

然后将插件添加到应用程序级 build.gradle (只需编辑文件):

 应用插件:'com.google.gms.google-services'

您应该有这样的东西:

  apply插件:'com.android.application'
适用插件: com.google.gms.google-services

android {
// ..
}

最后在应用程序级 build.gradle


$ b中添加依赖项$ b

 依赖项{
编译 com.google.android.gms:play-services:7.5.0
}


I'm trying a sample code which implements Google Cloud Messaging (GCM) and that is provided by google itself, GCM Demo.

I don't know how exactly I can add the dependencies

  • List item
  • Add the dependency to your project's top-level build.gradle:
  • When I go to Project Structure > Modules > Add and then select Module Dependency then a pop up screen appears for no module found to depend on. If there is another way I can add the dependencies then a help would be appreciated.I have attached an image regarding the same.

解决方案

As described in the link.

Add the dependency to your project's top-level build.gradle: (just edit the file)

classpath 'com.google.gms:google-services:1.3.0-beta1'

You should have somenthing 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'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Then add the plugin to your app-level build.gradle (just edit the file):

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

You should have somenthing like this:

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

android {
  //..
}

Finally add the dependency in your app-level build.gradle

dependencies {
  compile "com.google.android.gms:play-services:7.5.0"
}

这篇关于如何将依赖项添加到项目的顶级build.gradle文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆