必需:最新版本的Android Studio和Google Play服务
您可以通过更新顶级build.gradle和应用程序级别build.gradle文件来将插件添加到项目中,如下所示:
classpath 'com.google.gms:google-services:3.0.0'
喜欢
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
现在,您需要为Google Play服务添加依赖项。在应用程序的build.gradle中添加:
compile 'com.google.android.gms:play-services:9.6.1'
最后
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "// set Yours"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.android.support:appcompat-v7:24.2.0'
}
apply plugin: 'com.google.gms.google-services'