firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.28k stars 578 forks source link

:app:uploadCrashlyticsMappingFileRelease build task fails after upgrading to crashlytics plugin version 3.0.1 #5962

Closed SkillsDelivery closed 5 months ago

SkillsDelivery commented 6 months ago

Environment:

Problem description:

I just upgraded the version of "com.google.firebase.crashlytics" plugin from "2.9.9" to "3.0.1" and the build started to fail. Here is the build command which is failing:

./gradlew --parallel assemble

The build succeeds if I build only one build type at a time by running either

./gradlew --parallel assembleDebug

or

./gradlew --parallel assembleRelease

Logs:

> Task :app:uploadCrashlyticsMappingFileRelease FAILED
...
FAILURE: Build failed with an exception.
...
* What went wrong:
A problem was found with the configuration of task ':app:uploadCrashlyticsMappingFileRelease' (type 'UploadMappingFileTask').
  - Gradle detected a problem with the following location: 'C:\dev\coffee-beans\projects\quick-list-app\app\build\gmpAppId.txt'.

    Reason: Task ':app:uploadCrashlyticsMappingFileRelease' uses this output of task ':app:processDebugGoogleServices' without declaring an explicit or implicit dependency. This can lead to incorrect results being produc
ed, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':app:processDebugGoogleServices' as an input of ':app:uploadCrashlyticsMappingFileRelease'.
      2. Declare an explicit dependency on ':app:processDebugGoogleServices' from ':app:uploadCrashlyticsMappingFileRelease' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:processDebugGoogleServices' from ':app:uploadCrashlyticsMappingFileRelease' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.7/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

Relevant Code:

"com.google.gms.google-services" version: "4.4.1" "com.google.firebase:firebase-bom" version: "33.0.0"

Relevant parts of my app/build.gradle.kts file:

plugins {
    ...
    alias(libs.plugins.google.services)
    alias(libs.plugins.firebase.crashlytics)
   ...
}

android {
    ...
   buildTypes {
        debug {
            isDebuggable = true
            isMinifyEnabled = false
            manifestPlaceholders["crashlyticsCollectionEnabled"] = "false"
            configure<CrashlyticsExtension> { mappingFileUploadEnabled = false }
        }
        release {
            isDebuggable = false
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
            manifestPlaceholders["crashlyticsCollectionEnabled"] = "true"
            configure<CrashlyticsExtension> { mappingFileUploadEnabled = true }
        }
    }
}
...

Relevant parts of my AndroidManifest.xml file:

    <application ...>
        ...
        <meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="${crashlyticsCollectionEnabled}" />
        ...
    </application>

Releavant parts of my proguard-rules.pro file:

...
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
michaelaubertcmc commented 6 months ago

I have the same issue

:app:uploadCrashlyticsMappingFileVariant1BuildType1 uses this output of task ':app:processVariant2BuildType1GoogleServices' without declaring an explicit or implicit dependency

(notice the different variants)

But that happened while running gradle tasks without variants.

So: gradlew app:bundleBuildType1 fails but gradlew app:bundleVariant1BuildType1 and gradlew app:bundleVariant2BuildType1 both work fine.

lehcar09 commented 6 months ago

Hi @SkillsDelivery, thank you for reaching out. I was able to reproduce the issue. I'll notify our engineers and see what we can do here. Hang tight!

vullnetlimani commented 6 months ago

Same here as well.

We're encountering a recurring issue where the builds complete successfully, but towards the end, we encounter an error related to the Gradle task :app:uploadCrashlyticsMappingFileDevRelease. The specific problem identified by Gradle pertains to the location of a file at 'projectPath\app\build\gmpAppId.txt'

With 2.9.9 no prob.

mrober commented 6 months ago

Thanks for the reports and the output. The issue is the google-services plugin is outputting a file that Crashlytics consumes, but this file is getting clobbered when building multiple variants in a single build. I will fix this in google-services, then simply updating that plugin will resolve this issue.

For now, I have come up with a workaround you can do in your build.gradle.ktx file:

import com.google.gms.googleservices.GoogleServicesTask

project.afterEvaluate {
  tasks.withType<GoogleServicesTask> {
    gmpAppId.set(project.buildDir.resolve("$name-gmpAppId.txt"))
  }
}

dependencies {
  compileOnly("com.google.gms:google-services:4.4.1")
}

I will update this issue when the fix is released.

penkzhou commented 6 months ago

Thanks for the reports and the output. The issue is the google-services plugin is outputting a file that Crashlytics consumes, but this file is getting clobbered when building multiple variants in a single build. I will fix this in google-services, then simply updating that plugin will resolve this issue.

For now, I have come up with a workaround you can do in your build.gradle.ktx file:

import com.google.gms.googleservices.GoogleServicesTask

project.afterEvaluate {
  tasks.withType<GoogleServicesTask> {
    gmpAppId.set(project.buildDir.resolve("$name-gmpAppId.txt"))
  }
}

dependencies {
  compileOnly("com.google.gms:google-services:4.4.1")
}

I will update this issue when the fix is released.

That works.If you use build.gradle,the workaround can be:

import com.google.gms.googleservices.GoogleServicesTask

project.afterEvaluate {
  tasks.withType(GoogleServicesTask).configureEach {
    gmpAppId.set(new File(project.buildDir, "${name}-gmpAppId.txt"))
  }
}

dependencies {
  compileOnly("com.google.gms:google-services:4.4.1")
}
Philio commented 6 months ago

Thanks for the workaround @mrober, buildDir is deprecated, this small tweak worked:

project.afterEvaluate {
    tasks.withType<GoogleServicesTask> {
        gmpAppId.set(project.layout.buildDirectory.file("$name-gmpAppId.txt"))
    }
}
diareuse commented 5 months ago

If anybody wants to do this in Groovy

afterEvaluate {
    tasks.withType(com.google.gms.googleservices.GoogleServicesTask).configureEach {
        gmpAppId.set(layout.buildDirectory.file("$name-gmpAppId.txt"))
    }
}
tprochazka commented 5 months ago

The last working version of com.google.gms.google-services for me is 4.3.15, everything later was somehow broken related to Firebase functionality. I don't understand why it is so badly maintained, almost dead project, together with ever more read oss-licenses-plugin :-(. Why it is not part of the Firebase libraries ecosystem?

michaelaubertcmc commented 5 months ago

@tprochazka well, when a company lays off thousands of engineers, things move slower.

We now live in a world where the stock market measures perceived suffering instead of perceived value.

We have to suffer to make the investors happy. I don't like it either.

I'm sorry. I try to leave this stuff out of GitHub but you were wondering why this is happening.

tprochazka commented 5 months ago

@tprochazka Ohh :-( the same in our company. I hope that it is better in Google.

thatfiredev commented 5 months ago

Hey all, the version of google-services plugin that contains the fix for this issue (4.4.2) has been released: https://firebase.google.com/support/release-notes/android#google-services_plugin_v4-4-2

aantonic commented 5 months ago

I've upgraded google-service to 4.4.2, and it still fails

Uploading mapping file '/Users/runner/work/1/s/mobile/android/app/build/protected/bundle/flavorRelease/ProGuardMappingFile.txt' to Crashlytics

Task :app:protectAabFlavorRelease FAILED

FAILURE: Build failed with an exception.

mrober commented 5 months ago

@aantonic can you please run that task again with --stacktrace?

aantonic commented 5 months ago

It seems binary/source compatibility has been broken: (ai.digital.protectandroid is third-party component used for app protection)

Caused by: java.lang.NoSuchMethodError: 'void com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask.setMappingFileProvider(org.gradle.api.provider.Provider)' at ai.digital.protectandroid.protection.crashlytics.CrashlyticsMappingFileUploader.uploadMappingFile(CrashlyticsMappingFileUploader.kt:37) at ai.digital.protectandroid.protection.tasks.AppProtectionTask.applyProtection(AppProtectionTask.kt:90) at ai.digital.protectandroid.protection.tasks.AppProtectionTask.protectAab(AppProtectionTask.kt:75) at ai.digital.protectandroid.protection.tasks.AppProtectionTask.runProtection(AppProtectionTask.kt:26) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29) at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:248)

mrober commented 5 months ago

I am not sure about ai.digital.protectandroid.protection.crashlytics sorry. It looks like they rely on implementation details, not the public api, of the Crashlytics Gradle plugin. And after v3, the implementation is entirely different.

The v3 of the Crashlytics plugin gets the merged mapping file from AGP via SingleArtifact.OBFUSCATION_MAPPING_FILE. There is likely no need for this tool to call the Crashlytics plugin directly like that to set the mapping file.

This is an issue you can file with them. I am closing this one since the issue is with them. But feel free to reference this issue, and I don't mind providing them with any information if they need it.

SkillsDelivery commented 5 months ago

I upgraded crashlytics plugin to 3.0.1 and google-service plugin to 4.4.2 and now I could build with no problems. Everything seems to be fine now.

Thank you so much, guys! <3