microsoftconnect / ms-intune-app-sdk-android

Intune App SDK for Android enables data protection features and mobile app management via Microsoft Intune
43 stars 17 forks source link

App crash Issue with Flutter + Firebase #240

Closed asad-baidar closed 3 days ago

asad-baidar commented 3 weeks ago

Intune Android App SDK [Gradle Build Plugin] Issue with Flutter + Firebase

  1. Does your app compile and launch successfully without the Intune App SDK? [YES]
  2. Have you checked the [Microsoft Intune App SDK for Android] repository for similar issues? [YES, but none found]
  3. Are you using the latest version of the [SDK and Plugin]? [YES]

Summary

In Flutter Android app, when MAM is enabled it compiles and runs fine but when the inTune company portal is configured and we open the app, it crashes. When we remove Firebase dependencies then it works fine. no crash.

Details

Logs

Android Studio / Gradle 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)

Third-Party Library Dependencies

dart: ^3.4.4 flutter: ^3.24.0 firebase_core: ^3.0.0 firebase_messaging: ^15.0.0 firebase_crashlytics: ^4.0.0 firebase_analytics: ^11.0.0

jitheshncxe commented 2 weeks ago

Hi @asad-baidar could you please try with the latest version of firebase dependencies REF: https://firebase.google.com/support/release-notes/android and see if that helps. If the issue still exists with the latest version of dependencies, can you please share a repro project to investigate the issue further?

asad-baidar commented 2 weeks ago

Hi @jitheshncxe, let me try and get back. thanks.

asad-baidar commented 2 weeks ago

Hi @asad-baidar could you please try with the latest version of firebase dependencies REF: https://firebase.google.com/support/release-notes/android and see if that helps. If the issue still exists with the latest version of dependencies, can you please share a repro project to investigate the issue further?

Hi @jitheshncxe No luck with the latest firebase SDK. Here is a sample repository to test. https://github.com/asadbaidar/flutter_intune_project

jitheshncxe commented 1 week ago

Thanks, @asad-baidar for sharing the repo...I will try to reproduce the issue and update you...Thanks!

asad-baidar commented 4 days ago

Hi @jitheshncxe, is there any update?

asad-baidar commented 3 days ago

@jitheshncxe Issue resolved. 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"
  ...>
>
jitheshncxe commented 3 days ago

Thank you so much for the update and sharing the solution @asad-baidar...!