微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 如何将依赖项添加到项目的顶级build.gradle文件?

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

我不知道我究竟能添加依赖项

>列表项目
>将依赖项添加到项目的顶级build.gradle:
>当我进入项目结构>模块>单击添加然后选择模块依赖关系,然后会出现一个弹出屏幕,表示找不到依赖的模块.
如果还有另一种方法我可以添加依赖项,那么将会感谢帮助.我已经附加了关于相同的图像.

enter image description here

解决方法:

link所述.

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

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

你应该有这样的somenthing:

//顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项.

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
    }
}

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

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

你应该有这样的somenthing:

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

android {
  //..
}

最后在app-level build.gradle中添加依赖项

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐