dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

Android Binding didnt work on Maui #9263

Open matheusouz opened 2 months ago

matheusouz commented 2 months ago

Description

Hey everyone,

I recently ported my Xamarin.Forms app to .NET MAUI, which required updating some private bindings I had created. One of these bindings is for a library that provides extensive information about the phone. However, when I run the app on .NET MAUI, I encounter errors, and it just doesn’t work as expected. I’ve tried updating the dependencies, but without success.

Steps to Reproduce

1.  Open the forms-app project, build the binding project, and run the forms app. The output will be a Base64-encoded text containing some information.
2.  Repeat the process with the maui-app. This will trigger the issue.

Link to public reproduction project repository

https://github.com/matheusouz/dwn-binding-problem

Version with bug

8.0.71 SR7.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

is attached in repo
jpobst commented 2 months ago

Can you provide the errors you are seeing?

matheusouz commented 2 months ago

Hey @jpobst the full log is attached on the repo linked. But we have here too

2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.750 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
2024-08-29 18:44:36.751 18517-18555 f                       com.companyname.mauiapp              E  Exception: addInfo: addAndroidSensor, java.lang.IllegalStateException: @NotNull method kotlin/reflect/jvm/internal/impl/builtins/KotlinBuiltIns.getBuiltInClassByFqName must not return null
jpobst commented 2 months ago

Hmm, I haven't seen that error message before, but my guess is that the Java binaries are not making it into your final application.

https://learn.microsoft.com/en-us/dotnet/maui/migration/android-binding-projects?view=net-maui-8.0#embedded-jaraar-files

You might need to add one of these for *.jar files as well:

<DllFiles_net80_Android Include="bin\Release\net8.0-android\*.dll" />
<AarFiles_net80_Android Include="bin\Release\net8.0-android\*.aar" />

Also, you might want to switch to using the NuGet packages we maintain for your dependencies:

https://www.nuget.org/packages/Xamarin.Kotlin.Reflect https://www.nuget.org/packages/Xamarin.Protobuf.JavaLite

matheusouz commented 2 months ago

I didn’t include the .jar file because the binding doesn’t generate one. Regarding the packages, I tried using the latest versions, but without success.

I’m using these packages to demonstrate the binding working in Forms but not in MAUI.