Firebase错误-无法在Android Studio中计算属性“extraGeneratedResDir”的值

niwlg2el  于 2023-06-30  发布在  Android
关注(0)|答案(1)|浏览(81)

我正在Android Studio中使用Firebase数据库运行一个简单的应用程序-已在Firebase Jmeter 板上设置了项目并连接到我的Android Studio应用程序。在构建项目时,我得到了这个错误:

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(从Firebase控制台下载并粘贴到此处的应用程序目录(D:\work\Android Studio\FirebaseExample2\app)):

{
  "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"
}

下面是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.java

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);
            }
        });

    }
}

我已经尝试过禁用缓存并重新启动Android Studio,但问题仍然存在。
谢谢你!

dhxwm5r4

dhxwm5r41#

发现问题,是在build.gradle (Project: )文件中,具体是这一行:

classpath 'com.google.gms:google-services:4.3.10'

需要更改为:

classpath 'com.google.gms:google-services:4.3.15'

所以现在整个gradle文件是:

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
}

这无疑会随着新版本的发布而改变,但截至2023年6月28日,我的程序正在完美编译!

相关问题