Skip to content

Crashlytics plugin selects wrong applicationId - doesn't honour changes by setApplicationId() #1564

Closed

Description

@darrentaft

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository.
If you have a general question, need help debugging, or fall into some
other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 4.0 RC1
  • Firebase Component: Crashlytics Gradle Plugin
  • Component version: 2.1.0

[REQUIRED] Step 3: Describe the problem

My project uses a combination of flavorDimensions and buildTypes to generate 4 different apps with different app IDs. To do this, I use an "applicationVariants.all" loop to process the combination of flavors and types to decide on the applicationId to use.

The problem is that the Crashlytics plugin doesn't appear to honour the result - it's extracting config from google-services.json based on the default applicationId specified within the flavorDimension, rather than the dynamically configured one.

If I don't specify an applicationId in the flavors, it appears to read the package from the AndroidManifest.xml - which also isn't correct.

I can't see any way to tell Crashlytics which applicationId to use.

Steps to reproduce:

See test gradle config extract below.
Building "productaProdRelease" will correctly use applicationId "com.producta.app".
Building "productaNightlyRelease" will also use that same applicationId when deciding which part of google-services.json to use, even thought application will be built with applicationId "com.development-producta.app.something" as set by setApplicationId().

This results in crash reports being sent (according to the logcat console) but never actually appearing on the web site (I assume because they're sent to one project, with the applicationId from a different one).

Relevant Code:

flavorDimensions "PRODUCT", "TARGET"

productFlavors {
    producta {
        dimension "PRODUCT"
        applicationId "com.producta.app"
    }
    productb {
        dimension "PRODUCT"
        applicationId "com.productb.app"
    }
    nightly {
        dimension "TARGET"
    }
    sprint {
        dimension "TARGET"
    }
    prod {
        dimension "TARGET"
    }
}

buildTypes {
    debug {
    }
    release {
    }
    penTest {
    }
    store {
    }
}
    
applicationVariants.all { variant ->
    def mergedFlavor = variant.mergedFlavor

    if (variant.flavorName.startsWith("producta")) {
        if (variant.flavorName.contains("Prod")) {
            mergedFlavor.setApplicationId("com.producta.app")
        } else {
            mergedFlavor.setApplicationId("com.development-producta.app.something")
        }
    } else {
        if (variant.flavorName.contains("Prod")) {
            mergedFlavor.setApplicationId("com.productb.app")
        } else {
            mergedFlavor.setApplicationId("com.unrelated.app.something")
        }
    }
}

Activity

  1. JonWatson commented on May 26, 2020

    @JonWatson

    Seeing the same problematic behavior, thanks in advance

  2. mrwillis21 commented on May 26, 2020

    @mrwillis21
    Contributor

    Hi there! Just wanted to let folks know we're aware of this issue and working on getting a fix in for it. :)

    Thanks for the report!

  3. soenkegissel commented on Jun 8, 2020

    @soenkegissel

    Seeing the same problematic behavior, thanks in advance

  4. karthikrpandian commented on Jun 22, 2020

    @karthikrpandian

    We are also struggling with same issue

  5. soenkegissel commented on Jun 22, 2020

    @soenkegissel

    @mrwillis21 Could you please work in this issue next? Would be so happy.

  6. mrwillis21 commented on Jul 8, 2020

    @mrwillis21
    Contributor

    Hi @darrentaft (and others). I've been digging a bit more into this, and I'm not sure this is actually describing the issue I'd mentioned before that we knew about. I could use a bit more information. You mentioned:

    The problem is that the Crashlytics plugin doesn't appear to honour the result - it's extracting config from google-services.json based on the default applicationId specified within the flavorDimension, rather than the dynamically configured one.

    If I don't specify an applicationId in the flavors, it appears to read the package from the AndroidManifest.xml - which also isn't correct.

    Can you give me a sense of where you're seeing the incorrect application ID being used? I know you'd mentioned that you're not seeing your crash reports being sent up, but I'd like to understand better what you mean by "it's extracting config...". Can you give me an example of your build/run process where you're seeing the incorrect behavior?

  7. mrwillis21 commented on Jul 8, 2020

    @mrwillis21
    Contributor

    @JonWatson, @soenkegissel, or @karthikrpandian if you have examples of how this is affecting you, that would also help. :)

  8. JonWatson commented on Jul 9, 2020

    @JonWatson

    @mrwillis21 Do you have access to the support tickets from [email protected]? I have a case open with a lot of info.

    Case 00061830

    defaultConfig {
        applicationId "com.foo"
    }
    
    applicationVariants.all { variant ->
        def brand = variant.productFlavors.get(0).name
        if (brand == “blah”) {
            variant.mergedFlavor.applicationId = “com.foo.bar”
        } else {
            variant.mergedFlavor.applicationId = “com.foo.bar.zap”
        }
    }
    

    We are registering "com.foo.bar" and "com.foo.bar.zap" as the expected Application IDs in the Crashlytics console and google-services.json. The installed app has the expected Application ID of "com.foo.bar" or "com.foo.bar.zap"

    In the logs, I see: Sending app info to https://update.crashlytics.com/spi/v1/platforms/android/apps/com.foo. So however the Crashlytics SDK is determining the Application Id(Package Name), it is not respecting the variant.mergedFlavor override.

  9. soenkegissel commented on Jul 9, 2020

    @soenkegissel

    @mrwillis21 I can describe my issues as the exact same as mentioned by @JonWatson.

    The following will work with no problems. If I build for debug the google-services.json will search for com.company.coffeecup.debug. If this ID is not found build will fail. So everything as expected.

    defaultConfig {
        applicationId "com.company.coffeecup"
    }
    
    buildTypes {
            debug {
                applicationIdSuffix = ".debug"
            }
    }
    

    This will work as well. If in firebase console no com.company.coffeecup.huawei.debug or com.company.coffeecup.samsung is found, build will fail. Expected.

    defaultConfig {
        applicationId "com.company.coffeecup"
    }
    
    buildTypes {
            debug {
                applicationIdSuffix = ".debug"
            }
    }
    
    productFlavors {
    HUAWEI {
        dimension "vendor"
            applicationIdSuffix = ".huawei"
    }
    SAMSUNG {
        dimension "vendor"
           applicationIdSuffix = ".samsung"
    }
    FORSUMMER {
        dimension "season"
    }
    

    But here comes the problem. If I dynamically assign applicationIds with the following. Firebase (not only Crashyltics, but Analytics as well) will no honour this. It will look for e.g com.company.coffeecup.huawei.

    applicationVariants.all { variant ->
            def mergedFlavor = variant.mergedFlavor
            if (variant.productFlavors[2].name == "HUAWEI"
                && variant.productFlavors[3].name == "forChristmas") {
                mergedFlavor.setApplicationId("com.company.coffeecup.huawei.christmasedition")
            } else if (variant.productFlavors[2].name == "SAMSUNG"
                && variant.productFlavors[3].name == "FORSUMMER") {
                mergedFlavor.setApplicationId("com.company.coffeecup.samsung.summeredition")
            }
        }
    

    Gradle will honour the setApplicationId function and does correctly set ID. This screenshot is from Samsung Galaxy Store Dashboard
    image

    Everything set via mergedFlavor.setApplicationId is no honoured by firebase.

    In my firebase dashboard all analytics and crash reports for all editions and flavors (set via mergedFlavor.setApplicationId) is added to com.company.coffeecup.huawei instead of com.company.coffeecup.huawei.christmasedition, com.company.coffeecup.huawei.summeredition, com.company.coffeecup.huawei.kidsedition...

    Hope this helps.

  10. soenkegissel commented on Jul 9, 2020

    @soenkegissel

    Use this example to test:

    defaultConfig {
        applicationId "com.company.coffeecup"
    }
    
    buildTypes {
        productFlavors {
            HUAWEI {
                dimension "vendor" 
            }
            SAMSUNG {
                dimension "vendor"
            }
    }
    
    applicationVariants.all { variant ->
            //println("Iterating variant: " + variant.getName())
            def mergedFlavor = variant.mergedFlavor
            if (variant.productFlavors[1].name == "HUAWEI") {
                mergedFlavor.setApplicationId("com.company.coffeecup.willnotworkfor.huawei")
            } else if (variant.productFlavors[1].name == "SAMSUNG") {
                mergedFlavor.setApplicationId("com.company.coffeecup.willnotworkfor.samsung")
            }
        }
    

    This example will only look for com.company.coffeecup in google-services.json. Will not throw any errors for not finding com.company.coffeecup.willnotworkfor.huawei and does register both flavours as com.company.coffeecup.

  11. mrwillis21 commented on Jul 17, 2020

    @mrwillis21
    Contributor

    Thanks everyone for the examples!

    Firebase (not only Crashyltics, but Analytics as well)

    This is why I was asking -- I believe the problem may be broader than the Crashlytics plugin. Let me take all this info back to the team, and I'll let you know when I have more information to share. Thanks again!

  12. soenkegissel commented on Jul 20, 2020

    @soenkegissel

    This is why I was asking -- I believe the problem may be broader than the Crashlytics plugin. Let me take all this info back to the team, and I'll let you know when I have more information to share. Thanks again!

    Yes please take it to the team. I think there is a huge dark figure on this issue.

  13. mrwillis21 commented on Jul 21, 2020

    @mrwillis21
    Contributor

    Hi folks,

    For those of you experiencing this issue, do you have an app created in Firebase for each of your dynamic app IDs? For example, if you have com.foo, with two dynamic IDs: com.foo.debug and com.foo.release - do you have separate apps in the Firebase console for com.foo, com.foo.debug, and com.foo.release?

    Also, are your apps migrated from Fabric, or newly onboarded in Firebase?

  14. soenkegissel commented on Jul 21, 2020

    @soenkegissel

    do you have separate apps in the Firebase console for com.foo, com.foo.debug, and com.foo.release?

    Yes

    Also, are your apps migrated from Fabric, or newly onboarded in Firebase?

    Newly in firebase

  15. mrwillis21 commented on Jul 29, 2020

    @mrwillis21
    Contributor

    Hello again everyone!

    We believe we've tracked down the issue. It's related to the dynamically-set application ID not being picked up by the Google Services Plugin. This does cause downstream effects in Crashlytics, but also in other Firebase products, as has been shown.

    While we work to determine the best solution to this problem, we've found a simple workaround, which is to apply the Google Services Plugin after setting the application IDs in your applicationVariants block. So given the previous example:

    android {
        ...
    
        defaultConfig {
            applicationId "com.company.coffeecup"
        }
    
        flavorDimensions "vendor"
        productFlavors {
            HUAWEI {
                dimension "vendor" 
            }
            SAMSUNG {
                dimension "vendor"
            }
        }
    
        applicationVariants.all { variant ->
            def mergedFlavor = variant.mergedFlavor
            if (variant.productFlavors[0].name == "HUAWEI") {
                mergedFlavor.setApplicationId("com.company.coffeecup.willnotworkfor.huawei")
            } else if (variant.productFlavors[0].name == "SAMSUNG") {
                mergedFlavor.setApplicationId("com.company.coffeecup.willnotworkfor.samsung")
            }
        }
    
        ...
    }
    
    apply plugin: 'com.google.gms.google-services' // <--- MOVE THIS HERE
    

    Try this out and let us know how it goes, and I'll let you know when we have more details to share on this. :)

  16. vuhomobytelab commented on Aug 21, 2020

    @vuhomobytelab

    Hello again everyone!

    We believe we've tracked down the issue. It's related to the dynamically-set application ID not being picked up by the Google Services Plugin. This does cause downstream effects in Crashlytics, but also in other Firebase products, as has been shown.

    While we work to determine the best solution to this problem, we've found a simple workaround, which is to apply the Google Services Plugin after setting the application IDs in your applicationVariants block. So given the previous example:

    android {
        ...
    
        defaultConfig {
            applicationId "com.company.coffeecup"
        }
    
        flavorDimensions "vendor"
        productFlavors {
            HUAWEI {
                dimension "vendor" 
            }
            SAMSUNG {
                dimension "vendor"
            }
        }
    
        applicationVariants.all { variant ->
            def mergedFlavor = variant.mergedFlavor
            if (variant.productFlavors[0].name == "HUAWEI") {
                mergedFlavor.setApplicationId("com.company.coffeecup.willnotworkfor.huawei")
            } else if (variant.productFlavors[0].name == "SAMSUNG") {
                mergedFlavor.setApplicationId("com.company.coffeecup.willnotworkfor.samsung")
            }
        }
    
        ...
    }
    
    apply plugin: 'com.google.gms.google-services' // <--- MOVE THIS HERE
    

    Try this out and let us know how it goes, and I'll let you know when we have more details to share on this. :)

    Hi,
    I followed your solution but nothing happen.
    Crashlytics still get default config application ID.

    apply plugin: 'com.android.application'
    
    apply plugin: 'com.google.firebase.crashlytics'
    
    apply plugin: 'kotlin-android'
    
    apply plugin: 'kotlin-kapt'
    
    apply plugin: 'kotlin-android-extensions'
    
    android {
    ...
        defaultConfig {
            minSdkVersion 24
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
            flavorDimensions "default"
        }
        buildTypes {
            release {
                debuggable false
                minifyEnabled true
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        productFlavors {
            core {
                applicationId "com.example.core.dev"
            }
            appNameA {
                applicationId "com.example.appNameA"
            }
            appNameB {
                applicationId "com.example.something.appNameB"
            }
            appNameC {
                applicationId "com.example.appNameC"
            }
            appNameD {
                applicationId "com.example.someEnviroment.appNameD"
            }
        }
    ...
    }
    
    dependencies {
    ...
        // Firebase Crashlytics
        implementation 'com.google.firebase:firebase-core:17.5.0'
        implementation 'com.google.firebase:firebase-config:19.2.0'
        implementation 'com.google.firebase:firebase-analytics:17.5.0'
        implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
    ....
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    Thanks.

  17. JonWatson commented on Aug 21, 2020

    @JonWatson

    Hello again everyone!

    We believe we've tracked down the issue. It's related to the dynamically-set application ID not being picked up by the Google Services Plugin. This does cause downstream effects in Crashlytics, but also in other Firebase products, as has been shown.

    While we work to determine the best solution to this problem, we've found a simple workaround, which is to apply the Google Services Plugin after setting the application IDs in your applicationVariants block.

    This worked for us. Certainly not ideal but I'll take it! Thanks!

  18. mrwillis21 commented on Nov 19, 2020

    @mrwillis21
    Contributor

    Quick update to let you know that recent versions of the Google Services Plugin should no longer require this workaround. :)

  19. locked and limited conversation to collaborators on Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions