Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android studio 在Android库中为Google Play服务添加依赖项_Android Studio_Android Gradle Plugin_Google Play Services_Android Library - Fatal编程技术网

Android studio 在Android库中为Google Play服务添加依赖项

Android studio 在Android库中为Google Play服务添加依赖项,android-studio,android-gradle-plugin,google-play-services,android-library,Android Studio,Android Gradle Plugin,Google Play Services,Android Library,我正在开发一个依赖谷歌Play服务的Android库 Google提供的关于如何设置Google Play服务的说明只指定了将其添加到应用程序项目而不是库中时要遵循的步骤 我尝试对我的库执行相同的步骤,最后得到了以下build.gradle文件: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:

我正在开发一个依赖谷歌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.
我理解这一点,因为正如googleplayservices文档()中所述,它依赖于json文件进行配置。但是,由于我将其构建为一个库,因此我希望将google-services.json文件添加到将使用我的库的项目中,而不是将其放入库本身

那我该怎么做呢?我如何编译依赖于Google Play Services中定义的类的库,而不是在库中真正配置Google Play Services,并让使用我的库的应用程序来完成


谢谢大家!

您可以使用上的指令生成并添加
google services.json


它有一套逐步生成文件的指令。

比我想象的要简单


我所要做的就是从库的
build.gradle
文件中删除
classpath'com.google.gms:google services:2.0.0-alpha3'
apply plugin'com.google.gms.google services'
,然后只将它们添加到依赖于这个自定义库的应用程序项目中的gradle文件中。

我知道,问题是,我希望此文件由将使用我的库的应用程序生成。如果我根据您发布的说明生成文件,我的库将特定于单个项目。我认为如果不使用特定应用程序的客户端id,您无法以通用方式使用OAuth。允许这样做会破坏OAuth体系结构的全部目的。但是我有没有办法告诉Gradle只使用GooglePlay服务中定义的类编译库,而不在我的库中包含GooglePlay服务?我试着使用“提供的”,但它不起作用,因为它找不到Google Play服务中定义的资源。