【问题标题】:Build failed in add firebase when added apply plugin: 'com.google.gms.google-services'添加应用插件时添加 Firebase 构建失败:“com.google.gms.google-services”
【发布时间】:2025-12-02 08:15:01
【问题描述】:

当我在build.gradle(:app) 中添加这一行apply plugin: 'com.google.gms.google-services' 以将Firebase 添加到我的Android 应用程序时,我遇到了这个错误并且我没有找到任何日志来解决它!!

1-我加了google-services.json

2-我添加了这个implementation 'com.google.firebase:firebase-analytics:17.4.1'

3-我加了classpath 'com.google.gms:google-services:4.3.3'

4-我加了google()

没有这个apply plugin: 'com.google.gms.google-services' line 应用程序运行没有任何问题并且构建成功。

Build.gradle(module:app):

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


android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "xxxx"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'

    //Retrofit2
    implementation "com.squareup.retrofit2:retrofit:2.6.1"
    implementation "com.squareup.retrofit2:converter-gson:2.6.1"

    //RxJava2
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.11'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'

    //Koin dependency injection
    implementation "org.koin:koin-android:2.0.1"
    implementation "org.koin:koin-android-viewmodel:2.0.1"

    //PersistentCookieJar
    implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'

    //Image loader
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    kapt 'com.github.bumptech.glide:compiler:4.9.0'

    //MultiDex
    implementation 'com.android.support:multidex:1.0.3'

    //firebase
    implementation 'com.google.firebase:firebase-analytics:17.4.1'

    //Test
    testImplementation 'junit:junit:4.12'
    testImplementation "org.mockito:mockito-inline:3.0.0"
    testImplementation 'org.koin:koin-test:2.0.1'
    testImplementation "androidx.arch.core:core-testing:2.1.0"
    androidTestImplementation "org.mockito:mockito-inline:3.0.0"
    androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
}

Build.gradle(项目):

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

标签: android firebase kotlin gradle


【解决方案1】:

我检查了所有内容,似乎没问题,有时文件名和扩展名是问题:

  1. 从 Android Studio 中的 Build 菜单清理项目
  2. 检查您的文件名(如果有,请删除特殊字符或空格)
  3. 重建您的项目

希望对你有帮助;)

【讨论】: