How to add dependencies to project's top-level build.gradle file?

白昼怎懂夜的黑 提交于 2019-12-07 17:10:31

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/32113337/how-to-add-dependencies-to-projects-top-level-build-gradle-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!