Android – how do I add dependencies to the top-level build.gradle file of my project?

I'm trying a sample code to implement Google cloud messaging (GCM), which is provided by Google itself, GCM demo

I don't know if I can add dependencies

>List project > Add dependency to the top-level build.gradle of the project: > when I go to project structure > module > click Add and select module dependency, a pop-up screen will appear indicating that the dependent module cannot be found. If there is another way I can add dependency, I will thank you for your help. I have attached the same image

resolvent:

As described in

Add dependencies to the top-level build.gradle of the project: (just edit the file)

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

You should have something like this:

//Top level build file where you can add configuration options common to all subprojects / 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 plug-in to your application level build.gradle (just edit the file):

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

You should have something like this:

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

android {
  //..
}

Finally, add dependencies in app-level build.gradle

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>