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

Android Studio中Firebase项目构建报错:extraGeneratedResDir计算失败

解决Firebase项目构建错误:Querying the mapped value of provider before task processDebugGoogleServices has completed

错误信息

Execution failed for task ':app:mapDebugSourceSetPaths'.
> Error while evaluating property 'extraGeneratedResDir' of task ':app:mapDebugSourceSetPaths'
   > Failed to calculate the value of task ':app:mapDebugSourceSetPaths' property 'extraGeneratedResDir'.
      > Querying the mapped value of provider(java.util.Set) before task ':app:processDebugGoogleServices' has completed is not supported

构建堆栈跟踪

Executing tasks: [:app:assembleDebug] in project D:\work\Android Studio\FirebaseExample2

    Download https://plugins.gradle.org/m2/com/gradle/gradle-enterprise-gradle-plugin/3.10.2/gradle-enterprise-gradle-plugin-3.10.2.jar, took 1 s 705 ms (2.21 MB)
    > Task :app:createDebugVariantModel
    > Task :app:preBuild UP-TO-DATE
    > Task :app:preDebugBuild UP-TO-DATE
    > Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
    > Task :app:compileDebugAidl NO-SOURCE
    > Task :app:compileDebugRenderscript NO-SOURCE
    > Task :app:generateDebugBuildConfig
    > Task :app:javaPreCompileDebug
    > Task :app:checkDebugAarMetadata
    > Task :app:generateDebugResValues
    > Task :app:mapDebugSourceSetPaths FAILED
    > Task :app:generateDebugResources
    > Task :app:mergeDebugResources
    > Task :app:processDebugGoogleServices
    Execution optimizations have been disabled for task ':app:processDebugGoogleServices' to ensure correctness due to the following reasons:
      - Gradle detected a problem with the following location: 'D:\work\Android Studio\FirebaseExample2\app\build\generated\res\google-services\debug'. Reason: Task ':app:mergeDebugResources' uses this output of task ':app:processDebugGoogleServices' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.5/userguide/validation_problems.html#implicit_dependency for more details about this problem.
    > Task :app:packageDebugResources
    > Task :app:createDebugCompatibleScreenManifests
    > Task :app:extractDeepLinksDebug
    > Task :app:parseDebugLocalResources
    > Task :app:processDebugMainManifest
    > Task :app:processDebugManifest
    > Task :app:mergeDebugShaders
    > Task :app:compileDebugShaders NO-SOURCE
    > Task :app:generateDebugAssets UP-TO-DATE
    > Task :app:mergeDebugAssets
    > Task :app:compressDebugAssets
    > Task :app:processDebugJavaRes NO-SOURCE
    > Task :app:desugarDebugFileDependencies
    > Task :app:checkDebugDuplicateClasses
    > Task :app:mergeDebugJniLibFolders
    > Task :app:processDebugManifestForPackage
    > Task :app:mergeDebugJavaResource
    > Task :app:mergeExtDexDebug

google-services.json配置

文件已放置在app目录(D:\work\Android Studio\FirebaseExample2\app):

google-services.json文件目录位置

json内容:

{
  "project_info": {
    "project_number": "102836682558",
    "firebase_url": "https://example-d3da6-default-rtdb.firebaseio.com",
    "project_id": "example-d3da6",
    "storage_bucket": "example-d3da6.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:102836682558:android:b20556c6763de16c5c766f",
        "android_client_info": {
          "package_name": "com.enetapplications.firebaseexample"
        }
      },
      "oauth_client": [
        {
          "client_id": "102836682558-j851bq7699ovchhcufcn1o60jul1fpm3.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.enetapplications.firebaseexample",
            "certificate_hash": "1dad8469cb2080d8e92693b394b0791456170041"
          }
        },
        {
          "client_id": "102836682558-9rgt5a9e3s1305joulfhpugrjhdrpm7v.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyCKFtgpzJ7ITDeC8LBIysH1B5PyKjOrXJc"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "102836682558-9rgt5a9e3s1305joulfhpugrjhdrpm7v.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}

app级build.gradle配置

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

android {
    namespace 'com.enetapplications.firebaseexample'
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.enetapplications.firebaseexample"
        minSdkVersion 27
        targetSdkVersion 33
        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
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.firebase:firebase-database:20.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

MainActivity代码

package com.enetapplications.firebaseexample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class MainActivity extends AppCompatActivity {

    Button send;
    EditText name;

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference reference = database.getReference().child("users");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        name = findViewById(R.id.editText);
        send = findViewById(R.id.button);

        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String userName = name.getText().toString();
                reference.child("userName").setValue(userName);
            }
        });

    }
}

解决步骤

方案1:升级插件与依赖版本

  1. 打开项目根目录的build.gradle文件,更新google-services插件的classpath到最新稳定版(如4.4.0):
buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.4.0'
    }
}
  1. 打开app级build.gradle,更新Firebase Database依赖到最新版:
implementation 'com.google.firebase:firebase-database:20.3.0'
  1. 执行File > Sync Project with Gradle Files,然后重新构建项目。

方案2:添加显式任务依赖

在app级build.gradle的android代码块内添加如下配置,强制mergeDebugResources任务依赖processDebugGoogleServices:

tasks.whenTaskAdded { task ->
    if (task.name == 'mergeDebugResources') {
        task.dependsOn 'processDebugGoogleServices'
    }
}

同步Gradle后重新构建。

方案3:调整插件应用顺序

确保com.google.gms.google-services插件在所有Android相关插件之后应用,app级build.gradle的plugins块保持如下顺序:

plugins {
    id 'com.android.application'
    // 其他插件(如kotlin-android等)放在这里
    id 'com.google.gms.google-services'
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 23:37:01