You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle构建报错::app:processDebugGoogleServices任务配置问题求助

Android Gradle构建错误排查与解决

错误详情

构建时触发Gradle验证错误,核心提示如下:

  • 任务:app:processDebugGoogleServices(类型GoogleServicesTask)配置存在问题,涉及路径:C:\project\ocpp-android-master\app\build\generated\res\google-services\debug
  • 根本原因:任务:app:mergeDebugResources使用了:app:processDebugGoogleServices的输出产物,但未声明显式/隐式依赖,可能导致任务执行顺序混乱,引发构建异常

问题定位

从提供的build.gradle代码中可以看到,重复应用插件是引发该问题的主要原因:
在plugins代码块中已经声明了com.android.application和com.google.gms.google-services插件,但下方又通过apply plugin语句重复加载了这两个插件,导致Gradle任务依赖关系被打乱。

解决方案

步骤1:移除重复的插件应用

打开app模块的build.gradle文件,删除以下两行重复的插件加载代码:

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

步骤2(可选:若步骤1未彻底解决):显式声明任务依赖

如果移除重复插件后仍存在任务顺序问题,在build.gradle的android代码块中添加依赖配置,确保mergeDebugResources在processDebugGoogleServices完成后执行:

android {
    // 保留你项目原有的android配置(compileSdk、defaultConfig等)
    
    afterEvaluate {
        mergeDebugResources.dependsOn processDebugGoogleServices
    }
}

修改后的完整build.gradle示例

plugins {
    id 'com.android.application'
    id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
    id 'com.google.gms.google-services'
}

android {
    compileSdk 34

    defaultConfig {
        applicationId "your.app.package.name"
        minSdk 21
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    // 可选:显式任务依赖配置
    afterEvaluate {
        mergeDebugResources.dependsOn processDebugGoogleServices
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.7.6'
    implementation 'androidx.navigation:navigation-ui:2.7.6'
    implementation 'androidx.annotation:annotation:1.7.1'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'com.google.android.gms:play-services-maps:18.2.0'
    implementation 'com.android.billingclient:billing:6.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation platform('com.google.firebase:firebase-bom:32.7.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.android.gms:play-services-auth:20.7.0'

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

    implementation "androidx.recyclerview:recyclerview:1.3.2"
    implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'

    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'com.github.yuriy-budiyev:code-scanner:2.1.2'
}

内容的提问来源于stack exchange,提问作者sgzwiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 15:07:14