google-services插件无法检测到com.google.android.gms或com.google.firebase的任何版本 - 奇怪的行为

时间:2017-09-06 13:48:27

标签: android android-studio firebase android-gradle google-play-services

我有4个模块的项目:

  • app(主要)
  • 共LIB
  • C
  • d

我已将firebase正确设置为此处的状态:https://firebase.google.com/docs/android/setup

在我的 app模块中,我不使用任何其他库,只使用模块依赖项:

dependencies {
    debugCompile project(path: ':common-lib', configuration: 'debug')
    releaseCompile project(path: ':common-lib', configuration: 'release')
}

在我的 common-lib模块中,我使用了firebase库:

dependencies {
    (...)
    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'com.google.firebase:firebase-crash:11.2.0'
    compile 'com.google.firebase:firebase-messaging:11.2.0'
    compile 'com.google.firebase:firebase-config:11.2.0'
    compile 'com.google.firebase:firebase-ads:11.2.0'
}

在这种情况下项目编译,但我收到了消息:

google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.

当我将common-lib firebase依赖项复制到我的app模块时,消息消失了。

这是一个错误吗?我做错了吗?我的应用程序输出文件是否包含正确的11.2.0版本的firebase库,或者消息是否为9.0.0?

被修改

项目build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
            // Alternative URL is 'https://dl.google.com/dl/android/maven2/'
        }
        maven { url 'https://jitpack.io' }
    }
}

app module build.gradle

apply plugin: 'com.android.application'

android {
    (...)
}


dependencies {

    debugCompile project(path: ':common-lib', configuration: 'debug')
    debugTestCompile project(path: ':common-lib', configuration: 'debugTest')
    releaseCompile project(path: ':common-lib', configuration: 'release')

}

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

common-lib moudle build.gradle

apply plugin: 'com.android.library'


android {
    (...)
}
dependencies {
    (...)
    //firebase
    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'com.google.firebase:firebase-crash:11.2.0'
    compile 'com.google.firebase:firebase-messaging:11.2.0'
    compile 'com.google.firebase:firebase-config:11.2.0'
    compile 'com.google.firebase:firebase-ads:11.2.0'
}

2 个答案:

答案 0 :(得分:0)

您是否尝试添加此内容:

gradle文件的根级别中的

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

答案 1 :(得分:0)

我通过添加app (main)模块依赖项来解决这个问题:

implementation "com.google.firebase:firebase-core:$firebase_version"
implementation "com.android.support:appcompat-v7:$support_version"

现在,我的appcommon-lib (library)模块中存在以上依赖关系。 我还添加了$firebase_version$support_version,因此维护更容易。变量放在项目gradle.build

buildscript {

    ext {
        firebase_version = '11.8.0'
        support_version = '26.1.0'
    }
    (...)
}

问题出现是因为google-services插件会检查依赖项,并且在app gradle文件中找不到它。但它不会检查库依赖项,即使您通过将 implementation 更改为 api 来明确公开它:

common-lib gradle.build:

api "com.google.firebase:firebase-core:$firebase_version"
api "com.android.support:appcompat-v7:$support_version"

它仍然无法运作。