How can I resolve runtime crashes in a MAUI project when integrating Android libraries as AARs, despite resolving dependencies and fixing NoClassDefFoundError exceptions?

Megha Raypuriya 10 Reputation points
2025-01-27T13:44:34.9866667+00:00

We already have working libraries for iOS and Android, and now I’m trying to integrate them into a MAUI project. The iOS binding works fine, but I’m running into issues with the Android binding.

At first, I was getting NoClassDefFoundError exceptions. To fix it, I added all the necessary Maven dependencies as AAR or JAR files, and the dependencies seem to be resolved. But the app is still crashing at runtime in MAUI.

Is there anything else I should check or do when adding Android libraries as AARs in MAUI? Any tips to fix this would be super helpful!

Potential Crashed I found in logs, might help to identify issue

02:14.586 E/OplusTrack-ApkInfoUtil( 1966): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference
01-24 00:02:14.586 W/System.err( 1966): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference
01-24 00:02:14.587 W/System.err( 1966): 	at y6.a.a(ApkInfoUtil.java:6)
01-24 00:02:14.587 W/System.err( 1966): 	at r6.b.(TrackEvent.java:10)
01-24 00:02:14.587 W/System.err( 1966): 	at r6.a.(CommonBean.java:1)
01-24 00:02:14.587 W/System.err( 1966): 	at p6.f.b(OplusTrack.java:1)
01-24 00:02:14.587 W/System.err( 1966): 	at v6.b$c.d(AppLaunchEventRecorder.java:9)
01-24 00:02:14.587 E/Athena  ( 1966): MemoryGuardAction: handleAppChange
01-24 00:02:14.589 W/Battery ( 9155): ThermalControlUtils: mForegroundPkg=com.android.launcher
-----------------------------------------------------------------------------------------------
01-23 23:31:48.778 F/DEBUG   (31493):     x0  0000007dd2f4bd08  x1  0000007dd2f4bdd0  x2  0000007dd2f4bfa8  x3  0000007dd2f4bfac
01-23 23:31:48.778 F/DEBUG   (31493):     x4  0000007dd2f4ab70  x5  0000000014c47ec0  x6  b400007e592b4f00  x7  b400007e3d1cf800
01-23 23:31:48.778 F/DEBUG   (31493):     x8  0000007dd2f4bdd0  x9  0000000000000788  x10 0000000000000000  x11 0000000000000001
01-23 23:31:48.778 F/DEBUG   (31493):     x12 0000000000000004  x13 0c36e8713fd72ff9  x14 0000000000000006  x15 ffffffffffffffff
01-23 23:31:48.778 F/DEBUG   (31493):     x16 0000007dd01a7a98  x17 0000007ee29cd69c  x18 0000007dc25d4000  x19 0000007dd2f4bd08
01-23 23:31:48.778 F/DEBUG   (31493):     x20 0000007dd2f4bdd0  x21 0000000000000000  x22 00000000000000c8  x23 0000007dd2f4bff0
01-23 23:31:48.778 F/DEBUG   (31493):     x24 0000007eeb8e4980  x25 0000000000000002  x26 0000007eeb8e53c8  x27 0000000000000002
01-23 23:31:48.778 F/DEBUG   (31493):     x28 0000007dd2f4bec0  x29 0000007dd2f4bd50
01-23 23:31:48.778 F/DEBUG   (31493):     lr  0000007dd009e480  sp  0000007dd2f4bd00  pc  0000007dd009e4a4  pst 0000000020001000
01-23 23:31:48.778 F/DEBUG   (31493): backtrace:
01-23 23:31:48.778 F/DEBUG   (31493):       #00 pc 00000000002004a4  /data/app/~~FvLZ8FlErojfMYH9K17vFg==/com.companyname.mauisample-aX5f5eq4D0bVLnVPFrARow==/lib/arm64/libmonosgen-2.0.so (BuildId: 5c0f30dec901885b27282d3532d8efe2d5d00206)
01-23 23:31:48.778 F/DEBUG   (31493):       #01 pc 0000000000200338  /data/app/~~FvLZ8FlErojfMYH9K17vFg==/com.companyname.mauisample-aX5f5eq4D0bVLnVPFrARow==/lib/arm64/libmonosgen-2.0.so (BuildId: 5c0f30dec901885b27282d3532d8efe2d5d00206)
01-23 23:31:48.778 F/DEBUG   (31493):       #02 pc 000000000020a1d8  /data/app/~~FvLZ8FlErojfMYH9K17vFg==/com.companyname.mauisample-aX5f5eq4D0bVLnVPFrARow==/lib/arm64/libmonosgen-2.0.so (mono_assembly_name_new+36) (BuildId: 5c0f30dec901885b27282d3532d8efe2d5d00206)
01-23 23:31:48.778 F/DEBUG   (31493):       #03 pc 00000000000595c4  /data/app/~~FvLZ8FlErojfMYH9K17vFg==/com.companyname.mauisample-aX5f5eq4D0bVLnVPFrARow==/lib/arm64/libmonodroid.so (xamarin::android::Util::monodroid_load_assembly(void*, char const*)+48) (BuildId: 9b2ac0a5675842484749a6f6c33cdd76cea72d2c)

Document Reference :

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/native-library-interop/get-started

https://devblogs.microsoft.com/dotnet/native-library-interop-dotnet-maui/

https://github.com/CommunityToolkit/maui.nativelibraryinterop

Note : Some of the libraries used to build our android library are focused to support Kotlin Multi Platform(KMP).
Thanks, Megha

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,871 questions
Microsoft Intune iOS
Microsoft Intune iOS
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.iOS: An Apple mobile operating system.
250 questions
Microsoft Intune Android
Microsoft Intune Android
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Android: An open-source mobile platform based on the Linux kernel, developed by Google, and maintained by the Open Handset Alliance.
327 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.