如何向项目的顶级 build.gradle 文件添加依赖项? [英] How to add dependencies to project's top-level build.gradle file?
问题描述
我正在尝试实现 Google Cloud Messaging (GCM) 的示例代码,该代码由 google 自己提供,
如链接中所述.
将依赖项添加到您项目的顶级build.gradle
:(只需编辑文件)
classpath 'com.google.gms:google-services:1.3.0-beta1'
你应该有这样的东西:
//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项.
buildscript {存储库{jcenter()}依赖{类路径 'com.android.tools.build:gradle:1.3.0'类路径 'com.google.gms:google-services:1.3.0-beta1'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}
然后将插件添加到您的应用程序级build.gradle
(只需编辑文件):
应用插件:'com.google.gms.google-services'
你应该有这样的东西:
应用插件:'com.android.application'应用插件:'com.google.gms.google-services'安卓 {//..}
最后在你的应用级build.gradle
依赖项{编译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屋!