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

Camera view with .NET 9 crashes on Android #2438

Open
2 tasks done
jacobilsoe opened this issue Jan 13, 2025 · 10 comments · May be fixed by #2449
Open
2 tasks done

Camera view with .NET 9 crashes on Android #2438

jacobilsoe opened this issue Jan 13, 2025 · 10 comments · May be fixed by #2449
Labels
bug Something isn't working not-reproduced Couldn't reproduce the bug unverified

Comments

@jacobilsoe
Copy link

jacobilsoe commented Jan 13, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

There is an existing bug for this but it was closed and is now locked for updating: #2377

I have the exact same issue as described in that bug so I suspect it might not have been properly fixed.

My stacktrace:

01-13 13:49:15.312 F/mono-rt ( 5558): [ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method not found: void AndroidX.Camera.Core.Preview.SetSurfaceProvider(AndroidX.Camera.Core.Preview/ISurfaceProvider)
01-13 13:49:15.312 F/mono-rt ( 5558): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[d__14](d__14& stateMachine)
01-13 13:49:15.312 F/mono-rt ( 5558): at CommunityToolkit.Maui.Core.CameraManager.StartUseCase(CancellationToken token)
01-13 13:49:15.312 F/mono-rt ( 5558): at CommunityToolkit.Maui.Core.CameraManager.<>c__DisplayClass41_0.<b__0>d.MoveNext() in /_/src/CommunityToolkit.Maui.Camera/CameraManager.android.cs:line 164
01-13 13:49:15.312 F/mono-rt ( 5558): --- End of stack trace from previous location ---
01-13 13:49:15.312 F/mono-rt ( 5558): at System.Threading.Tasks.Task.<>c.b__128_0(Object state)
01-13 13:49:15.312 F/mono-rt ( 5558): at Android.App.SyncContext.<>c__DisplayClass2_0.b__0() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:line 36
01-13 13:49:15.312 F/mono-rt ( 5558): at Java.Lang.Thread.RunnableImplementor.Run() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:line 37
01-13 13:49:15.312 F/mono-rt ( 5558): at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net9.0/android-35/mcw/Java.Lang.IRunnable.cs:line 59
01-13 13:49:15.312 F/mono-rt ( 5558): at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22

Expected Behavior

No crash

Steps To Reproduce

See Current Behavior

Link to public reproduction project repository

https://github.com/MarianHristov92/MauiCameraViewNet9

Environment

- .NET MAUI CommunityToolkit:10.0.0
- .NET MAUI CommunityToolkit.Maui.Camera: 2.0.0
- OS: ANDROID 15
- .NET MAUI: 9.0.22

Anything else?

No response

@jacobilsoe jacobilsoe added bug Something isn't working unverified labels Jan 13, 2025
@standamikes
Copy link

same here. We are unable to migrate to .net 9 because of that

@sstobinski
Copy link

same here.

@UlriCode
Copy link

I have the same issue.

The problem is that the CommunityToolkit uses outdated NuGet for Xamarin.AndroidX.Camera.Camera2 and Xamarin.AndroidX.Camera.View.
And when you are using another NuGet that uses a more recent version of those packages, thanks to the lowest applicable version rule, the most recent package is used, which is not compatible with the CommunityToolkit.

To fix this problem, I've only changed 2 things:

  • In CommunityToolkit.Maui.Camera.csproj
    Image
  • In CameraManager.android.cs
    Image

Here is the NuGet that includes those changes if anyone wants to try it:
CommunityToolkit.Maui.Camera.2.0.0-fix.nupkg.zip

@bijington
Copy link
Contributor

@UlriCode would you be willing to open a PR to resolve this?

UlriCode added a commit to UlriCode/Maui that referenced this issue Jan 16, 2025
@UlriCode UlriCode linked a pull request Jan 16, 2025 that will close this issue
6 tasks
@UlriCode
Copy link

@UlriCode would you be willing to open a PR to resolve this?

I've just opened a PR: #2449
It's my first one and it looks like it is missing things so it may not be accepted.
I also needs to agree with the CLA, and I need my boss approval for that, so I won't be able to do it before Monday.

@brminnick
Copy link
Collaborator

I am unable to reproduce this error. @bijington Are you able to reproduce the reported crash?

I confirmed that the provided reproduction sample works on both my Android Emulator (Android API 35) and my Google Pixel (Android API 31). I also confirmed that the CameraView page in our Community Toolkit Sample app works on my Android Emulator (Android API 35).

@UlriCode Could you please provide more information on how to reproduce the crash? We are blocked from merging your PR until we can reproduce the existing error and confirm that your PR fixes it.

Reproduction Sample (Google Pixel on Android API 31) Reproduction Sample (Android Emulator API 35) CommunityToolkit.Maui.Sample (Android Emulator API 35)
Image Image Image

@brminnick brminnick added needs reproduction not-reproduced Couldn't reproduce the bug labels Jan 16, 2025
Copy link
Contributor

Hi @jacobilsoe! We have added the needs reproduction label to this issue, which indicates that we are unable to take further action until you provide a reproduction sample that we can use to reproduce + fix your bug. In accordance with the Reporting a bug section of our Contributing.md that you confirmed reading before you submitted this Issue, we ask that every Issue author provide a link to an open-source repository containing the reproduction sample app. This issue will be closed automatically in 5 days if we do not receive a reproduction sample from you. Please feel free to re-open this Issue once you have provided a reproduction sample.

@UlriCode
Copy link

UlriCode commented Jan 17, 2025

@brminnick here is a crude project that reproduce the problem: Pizzaui.zip

Just tap on "ShowCameraView" to see the crash.

This project contains another NuGet BarcodeScanning.Native.Maui that needs Xamarin.AndroidX.Camera.Camera2 and Xamarin.AndroidX.Camera.View v1.4.1.
Because of that, this is the version used for the final app.

If you remove BarcodeScanning.Native.Maui from the project (and comment the code that needs it) and clear bin/obj, the final app will contain Xamarin.AndroidX.Camera.Camera2 and Xamarin.AndroidX.Camera.View v1.3.1.1, so the CameraView will work.

@jacobilsoe
Copy link
Author

@UlriCode Yep, I also use BarcodeScanning.Native.Maui. So makes sense I see the issue as well. 👍

@bijington
Copy link
Contributor

@UlriCode thank you for the investigation there to work out the issue. It makes sense why @brminnick couldn't reproduce the issue.

What I propose is that we thoroughly test that this new version doesn't introduce any issues and if all is fine we merge 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not-reproduced Couldn't reproduce the bug unverified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants