firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

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

Open SkillsDelivery opened this issue 9 months ago • 5 comments

Environment:

  • Android Studio version: Jellyfish (2023.3.1)
  • Firebase Component: Crashlytics
  • Component version: 3.0.1

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

SkillsDelivery avatar May 14 '24 09:05 SkillsDelivery

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.

michaelaubertcmc avatar May 14 '24 13:05 michaelaubertcmc

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!

lehcar09 avatar May 14 '24 13:05 lehcar09

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.

vullnetlimani avatar May 14 '24 14:05 vullnetlimani

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.

mrober avatar May 14 '24 15:05 mrober

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

penkzhou avatar May 16 '24 02:05 penkzhou

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

Philio avatar May 17 '24 17:05 Philio

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

diareuse avatar May 30 '24 09:05 diareuse

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?

tprochazka avatar May 30 '24 20:05 tprochazka

@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.

michaelaubertcmc avatar May 31 '24 06:05 michaelaubertcmc

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

tprochazka avatar May 31 '24 10:05 tprochazka

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

thatfiredev avatar May 31 '24 11:05 thatfiredev

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.

  • What went wrong: Execution failed for task ':app:protectAabFlavorRelease'.

'void com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask.setMappingFileProvider(org.gradle.api.provider.Provider)'

aantonic avatar Jun 03 '24 09:06 aantonic

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

mrober avatar Jun 03 '24 14:06 mrober

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

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:protectAabFlavorRelease'.

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)

aantonic avatar Jun 04 '24 06:06 aantonic

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.

mrober avatar Jun 04 '24 18:06 mrober

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

SkillsDelivery avatar Jun 04 '24 19:06 SkillsDelivery