Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rbakhshi opened this issue Feb 21, 2024 · 5 comments
Closed

Comments

@rbakhshi
Copy link

rbakhshi commented Feb 21, 2024

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
Copy link
Contributor

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

@tanderson-ld
Copy link
Contributor

tanderson-ld commented Feb 21, 2024

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
Copy link
Author

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
Copy link
Author

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

@tanderson-ld
Copy link
Contributor

No worries! Thank you for engaging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants