firebase / firebase-android-sdk

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

FirebaseCore: App crashes when launched with InTune MAM enabled #6220

Closed asad-baidar closed 3 days ago

asad-baidar commented 2 weeks ago

Environment

Problem

In Flutter Android app, when MAM is enabled it compiles and runs fine but when the inTune company portal app is installed and configured on the device, the App crashes on launch. When we remove Firebase dependencies then App works fine and does not crash.

Steps to reproduce:

In the Flutter application, add inTune SDK dependencies in Android Gradle files. Install InTune company portal app and configure the MAM. Now launching the Flutter MAM app will crash.

Relevant Code:

No code required, just add the SDK dependencies in gradle and enable InTune gradle plugin.

build.gradle

plugins {
    .......
    id 'com.microsoft.intune.mam'
}

and SDK AAR Intune Android App SDK Version: 10.3.1

Crash Logs:

Initializing Firebase Sessions SDK.
Failed to register lifecycle callbacks, unexpected context class com.microsoft.intune.mam.client.content.MAMContext.
Shutting down VM
FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassCastException: com.microsoft.intune.mam.client.content.MAMContext cannot be cast to android.app.Application
at android.app.ActivityThread.installProvider(ActivityThread.java:7464)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6976)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6747)
at android.app.ActivityThread.access$1500(ActivityThread.java:256)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7870)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.ClassCastException: com.microsoft.intune.mam.client.content.MAMContext cannot be cast to android.app.Application
at com.google.android.gms.internal.measurement.zzdn.<init>(com.google.android.gms:play-services-measurement-sdk-api@@22.0.1:111)
at com.google.android.gms.internal.measurement.zzdn.zza(com.google.android.gms:play-services-measurement-sdk-api@@22.0.1:36)
at com.google.firebase.analytics.connector.AnalyticsConnectorImpl.getInstance(com.google.android.gms:play-services-measurement-api@@22.0.1:35)
at com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar.lambda$getComponents$0(com.google.android.gms:play-services-measurement-api@@22.0.1:5)
at com.google.firebase.analytics.connector.internal.zzc.create(Unknown Source:0)
at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0$com-google-firebase-components-ComponentRuntime(ComponentRuntime.java:160)
at com.google.firebase.components.ComponentRuntime$$ExternalSyntheticLambda2.get(D8$$SyntheticClass:0)
at com.google.firebase.components.Lazy.get(Lazy.java:53)
at com.google.firebase.components.ComponentRuntime.doInitializeEagerComponents(ComponentRuntime.java:322)
at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(ComponentRuntime.java:312)
at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:607)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:300)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:249)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:69)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2404)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2374)
at com.microsoft.intune.mam.client.content.MAMContentProvider.attachInfoReal(MAMContentProvider.java:188)
at java.lang.reflect.Method.invoke(Native Method)
at o.writeMessageNoTag$INotificationSideChannelDefault.invoke(:84)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy8.attachInfoReal(Unknown Source)
at com.microsoft.intune.mam.client.content.ContentProviderBehaviorImpl.attachInfoMAM(:454)
at java.lang.reflect.Method.invoke(Native Method)
at o.writeMessageNoTag$INotificationSideChannelDefault.invoke(:84)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy7.attachInfoMAM(Unknown Source)
at com.microsoft.intune.mam.client.content.MAMContentProvider.attachInfoMAM(MAMContentProvider.java:343)
at com.google.firebase.provider.FirebaseInitProvider.attachInfoMAM(FirebaseInitProvider.java:61)
at java.lang.reflect.Method.invoke(Native Method)
at o.writeMessageNoTag$INotificationSideChannelDefault.invoke(:84)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy8.attachInfoMAM(Unknown Source)
at com.microsoft.intune.mam.client.content.ContentProviderBehaviorImpl.attachInfo(:179) (Ask Gemini)
at java.lang.reflect.Method.invoke(Native Method)
at o.writeMessageNoTag$INotificationSideChannelDefault.invoke(:84)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy7.attachInfo(Unknown Source)
at com.microsoft.intune.mam.client.content.MAMContentProvider.attachInfo(MAMContentProvider.java:67)
at android.app.ActivityThread.installProvider(ActivityThread.java:7459)
google-oss-bot commented 2 weeks ago

I found a few problems with this issue:

asad-baidar commented 2 weeks ago

Here is a sample repository to test. https://github.com/asadbaidar/flutter_intune_project

lehcar09 commented 2 weeks ago

Hi @asad-baidar, thank you for reaching out. I tried reproducing the issue, however, I'm encountering a different issue.

I ran the following commands:

// To configure the apps
$ flutterfire configure
// and
$ flutter pub get
$ dart run build_runner build --delete-conflicting-outputs
$ cd app/kanban
$ flutter run --flavor dev --target lib/main_dev.dart

Then, below is the error I'm getting

Screenshot 2024-08-28 at 6 54 27 PM

I'm not familiar with the Inture MAM. However, The ClassCastException suggests that the app is trying to cast an object of type com.microsoft.intune.mam.client.content.MAMContext to android.app.Application. This likely happens because of a conflict between Firebase and Microsoft Intune MAM integration.

Have you tried running your app with Firebase integration only? This will help us eliminate a possible issue that Firebase is not being initialized properly

asad-baidar commented 2 weeks ago

Hi @lehcar09 Thank you for looking into it. I just pushed a fix. please take the pull again and run clean. And no need to run flutterfire configure. as the project already has firebase configured.

And yes when I build without Firebase but keep Intune, it works fine. no crash then. same with removing Intune but keeping Firebase also works.

about cast issue it is within the Firebase SDK which should not occur as Context is not an instance of Application maybe something is wrong with the Firebase?

lehcar09 commented 2 weeks ago

Hey @asad-baidar, I tried running your MCVE again and the app launched without any issue.

Screenshot 2024-08-30 at 1 31 08 AM

The only difference in the setup you share is that I ran the flutterfire configure that generates the firebase_options file that contains the Firebase configuration as mentioned in our documentation.

Can you share how you initialize Firebase?

asad-baidar commented 2 weeks ago

Hi @lehcar09 I added the google-services.json for configuration. firebase app automatically pick those if not provided in flutter init.

Secondly you need to install Intune company portal first in the phone. Intune SDK gets activated when that is configured. its then the app starts crashing. as I mentioned in the initial description. without intune setup, app works fine.

lehcar09 commented 2 weeks ago

Hey @asad-baidar, thank you for your clarification. Per checking with our engineers, based on your logs, the cause of the exception is Caused by: java.lang.ClassCastException: com.microsoft.intune.mam.client.content.MAMContext cannot be cast to android.app.Application that seems to be related this MS Intune Android SDK issue (#172).

Could you check if the solution shared in this comment will resolve your issue?

asad-baidar commented 2 weeks ago

Hey @asad-baidar, thank you for your clarification. Per checking with our engineers, based on your logs, the cause of the exception is Caused by: java.lang.ClassCastException: com.microsoft.intune.mam.client.content.MAMContext cannot be cast to android.app.Application that seems to be related this MS Intune Android SDK issue (#172).

Could you check if the solution shared in this comment will resolve your issue?

Hi @lehcar09 Yes I previously checked that comment and manifest in flutter already uses FlutterApplication and there seems to be nothing wrong there. As that comment says he missed the application tag but I didn't.

daymxn commented 1 week ago

@asad-baidar This may have something to do with android level API changes. What phone are you using, and what API level is it?

asad-baidar commented 1 week ago

@asad-baidar

This may have something to do with android level API changes. What phone are you using, and what API level is it?

@daymxn min API is 28 and building with 34. Used pixel and xiaomi phones and emulators. All behave same.

asad-baidar commented 4 days ago

Hi @lehcar09 , is there any update?

asad-baidar commented 3 days ago

@lehcar09 you were right. I thought Flutter always uses FlutterApplication instead of android.app.Application, but it turns out it doesn’t so I can safely replace name tag with com.microsoft.intune.mam.client.app.MAMApplication. This fixed the crash and it is working well now. Closing the issue. Thank you.

<manifest
  ...  
  <application
  ...
  android:name="com.microsoft.intune.mam.client.app.MAMApplication"
  ...>
>