CommunityToolkit / Maui.NativeLibraryInterop

Maui.NativeLibraryInterop is a community-created library of binding samples to help .NET MAUI developers interop with native libraries more easily
MIT License
183 stars 29 forks source link

Runtime Dependencies/Complex Example #41

Open kfrancis opened 4 months ago

kfrancis commented 4 months ago

I've been trying to create a binding for Intercom, but I'm struggling to run it on Android even though it's all building. Can there be a sample that has a deeper dependency tree and includes Android? Right now, the Facebook example is the only Android example but there are no run-time dependencies only compile-time.

Perhaps an example that packs up the work into a plugin? https://github.com/jfversluis/Plugin.Maui.Feature

Links:

kfrancis commented 3 months ago

Started trying to make sense of this here: https://github.com/kfrancis/Plugin.Maui.Intercom

kfrancis commented 3 months ago

Getting closer, able to call initialize but when trying to render the component I'm getting:

Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/compose/runtime/internal/ComposableLambdaKt;'

Still a mess of dependencies, and the error it's mentioning isn't a direct one but rather transient from one of the material dependencies: https://mvnrepository.com/artifact/io.intercom.android/intercom-sdk-base/15.10.1

2024-08-07-0z7d7

rachelkang commented 2 months ago

Hi, @kfrancis - thanks for using Maui.NativeLibraryInterop and reporting this issue. It appears that you might be missing some dependencies that your binding library of interest requires. In case it is helpful, I have a sample that includes an Android binding with its dependencies at https://github.com/rachelkang/MauiCharts and more information about my process in a blog post .

kfrancis commented 2 months ago

@rachelkang I did check the blog post and your source, but I don't see where my issue lies. I mean, Intercom has many runtime dependencies whereas your project is single-dependency. In particular, the compose dependency seems to be more problematic than others - but I'm not sure where I'm going about it wrong.

https://github.com/kfrancis/Plugin.Maui.Intercom/blob/a5e09782ae77924e350290dba262aeda84a5d9cd/src/Plugin.Maui.Feature/Plugin.Maui.Intercom.csproj#L86

https://github.com/kfrancis/Plugin.Maui.Intercom/blob/a5e09782ae77924e350290dba262aeda84a5d9cd/src/android/native/mauiintercom/build.gradle.kts#L39

Any further suggestions? I put the source on github in the hopes that it might be useful to see what's going on in a far more dependency-complex scenario.

rachelkang commented 1 month ago

Hi, @kfrancis - I recommend double-checking the versions of your dependencies and ensuring they're all compatible with one another / there is no mismatch. If you continue to have issues, I recommend consulting on the issue with the library, as it may be a compatibility issue they have with Android.

Similar Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/compose/runtime/internal/ type issues seem to commonly be due to version mismatches - e.g. https://stackoverflow.com/questions/66429770/jetpack-compose-fails-with-noclassdeffounderror-failed-resolution-of-landroidx

HomeroLara commented 1 month ago

Hi @kfrancis I'm dealing with a similar situation for Android. I'm able to compile with no issue but when I try to initialize the native Android Binding library at runtime, I get a 'java.lang.ClassNotFoundException' exception. I'm thinking the native library has run-time dependencies as well. Question: The dependencies you've listed on your Aug 7 post, are those all the dependencies that your binding needs or did you come up with that list some other way? I ask because the dependencies list at Maven show several more than that post. Thanks for your post!

kfrancis commented 1 month ago

I was mainly going from Intercom's android example, but yes - I agree, Maven lists far more.

This is rough, because I'm trying to migrate from Xamarin in which someone kindly had and relatively maintained bindings and it worked great but they aren't and it doesn't, and the binding story for Maui is in it's infancy and complex.