【发布时间】:2016-01-08 19:12:38
【问题描述】:
我正在开发一个依赖于 Google Play 服务的 Android 库。
Google 提供的关于如何设置 Google Play 服务的说明仅指定了将其添加到应用程序项目而不是库时要遵循的步骤。
我尝试对我的库执行相同的步骤,最终得到以下 build.gradle 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-annotations:+'
provided 'com.google.android.gms:play-services-auth:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
这样做的问题是,在构建项目时,我得到以下异常:
* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it.
我理解这一点,因为正如 Google Play 服务文档 (https://developers.google.com/android/guides/setup) 中所述,它依赖于 json 文件进行配置。但是,由于我将其构建为库,因此我希望将 google-services.json 文件添加到将使用我的库而不是将其放入库本身的项目中。
那么我该怎么做呢?如何编译依赖于 Google Play 服务中定义的类但并未真正在库中配置 Google Play 服务并让它由使用我的库的应用程序完成的库?
谢谢!
【问题讨论】:
标签: android-studio android-gradle-plugin google-play-services android-library