launchdarkly / dotnet-client-sdk

LaunchDarkly Client-side SDK for .NET
Other
7 stars 8 forks source link

Support for MAUI Android app on .NET8 and targeting Android Api 34 #89

Closed rbakhshi closed 9 months ago

rbakhshi commented 9 months ago

Describe the bug MAUI application using .NET 8 and targeting Android Api 34 crash on intialising the LD client.

To reproduce

  1. Create a sample MAUI project using .NET8
  2. Make sure target-sdk is 34 for Android (AndroidManifest.xml)
  3. Run the sample to make sure it works on Android simulator
  4. Add a reference to LaunchDarkly.ClientSdk v5 nuget
  5. Set it up to initialize the SDK
  6. Try running the sample project again

Expected behavior The app should run be able to fetch feature flags

What goes wrong The app crashes with following error:

System.TypeInitializationException: The type initializer for 'LaunchDarkly.Sdk.Client.PlatformSpecific.PlatformConnectivity' threw an exception.
    ---> Java.Lang.SecurityException: com.my.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
    ---> Android.OS.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720)
    at android.os.Binder.execTransactInternal(Binder.java:1339)
    at android.os.Binder.execTransact(Binder.java:1275)

    --- End of managed Android.OS.RemoteException stack trace ---
android.os.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720)
    at android.os.Binder.execTransactInternal(Binder.java:1339)
    at android.os.Binder.execTransact(Binder.java:1275)

    --- End of managed Android.OS.RemoteException stack trace ---
android.os.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720)
    at android.os.Binder.execTransactInternal(Binder.java:1339)
    at android.os.Binder.execTransact(Binder.java:1275)

    --- End of inner exception stack trace ---
    at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualObjectMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args)
    at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualObjectMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters)
    at Android.Content.ContextWrapper.RegisterReceiver(BroadcastReceiver receiver, IntentFilter filter)
    at Microsoft.Maui.Networking.ConnectivityImplementation.StartListeners()
    at Microsoft.Maui.Networking.ConnectivityImplementation.add_ConnectivityChanged(EventHandler`1 value)
    at LaunchDarkly.Sdk.Client.PlatformSpecific.PlatformConnectivity..cctor()
    --- End of managed Java.Lang.SecurityException stack trace ---
java.lang.SecurityException: com.my.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
    at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
    at android.os.Parcel.createException(Parcel.java:3041)
    at android.os.Parcel.readException(Parcel.java:3024)
    at android.os.Parcel.readException(Parcel.java:2966)
    at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
Caused by: android.os.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720)
    at android.os.Binder.execTransactInternal(Binder.java:1339)
    at android.os.Binder.execTransact(Binder.java:1275)

Logs Stack trace available above

SDK version v5

Language version, developer tools MAUI .NET8 Android target sdk 34

OS/platform Build on Windows and run on Android

Additional context Targeting sdk version 33 is fine but there is a deadline of August 2024 before all apps need to target sdk 34

tanderson-ld commented 9 months ago

Thank you for opening this @rbakhshi. I spent some time looking through https://github.com/dotnet/maui/issues/17861 but need to investigate more today.

tanderson-ld commented 9 months ago

What specific version for .NET 8 does your sample app end up on? It looks like it should be fixed by 8.0.6.

Fix broadcast receiver register on android 14.0/34+ by @Redth in https://github.com/dotnet/maui/pull/18520
rbakhshi commented 9 months ago

hmm... we are using net 8.0.200 with maui 8.0.3. Thanks for the update. Will try 8.0.7 see how it goes

rbakhshi commented 9 months ago

@tanderson-ld you are right. All good. closing this

tanderson-ld commented 9 months ago

No worries! Thank you for engaging!