Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [MauiCompat] Xamarin.CommunityToolkit.MauiCompat CameraView produces Android No view found for fragment CameraFragment error #1914

Open
julianadormon opened this issue Sep 29, 2022 · 7 comments
Labels
bug Something isn't working. Breaky break. maui-compat

Comments

@julianadormon
Copy link

Thanks in advance!! I'm quite new to XAML so be kind :)

Description

My requirement is to add a CameraView to a .net Maui app which runs on Android and iOS. I understand that there is no CameraView in the Maui.Community.Toolkit but I was under the impression, which may be wrong, that I could run the Xamarin.Community.Tookit.MauiCompat packages which I'm trying to do in the code below.

Stack Trace

--- End of managed Java.Lang.IllegalArgumentException stack trace ---
java.lang.IllegalArgumentException: No view found for id 0x1 (unknown) for fragment CameraFragment{4e42a40} (ddc40138-4928-4ebc-bfd4-b5fb0b1cacdc id=0x1 tag=camera)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1758)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2849)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2784)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:262)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:478)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1455)
at android.app.Activity.performStart(Activity.java:8076)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3660)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Link to Reproduction Sample

I posted my code to stack-overflow but if you need a repo, please let me know:
https://stackoverflow.com/questions/73889560/xamarin-communitytoolkit-mauicompat-cameraview-produces-android-no-view-found-fo

Steps to Reproduce

  1. Create a .net Maui Blazor app
  2. Install and use Xamarin.CommunityToolkit.MauiCompat in MauiProgram.cs
  3. Configure handlers
  4. Add CameraView to XAML and appropriate Event Callbacks as per this demo
    https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Views/CameraViewPage.xaml
    https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Views/CameraViewPage.xaml.cs
  5. Run degug to Android Emulator Pixel 5 (API 31)

Expected Behavior

Expect program to build and run

Actual Behavior

Program errors with Java error

Basic Information

  • Version with issue:
  • Last known good version: Xamarin.CommunityToolkit.MauiCompat 2.0.2 1013
  • IDE: Visual Studio Community 2022 for Mac Preview Version 17.4 Preview (17.4 build 1583)
  • Platform Target Frameworks: Android, iOS

Visual Studio Community 2022 for Mac Preview
Version 17.4 Preview (17.4 build 1583)
Installation UUID: 0b36004a-e5d9-4978-ae2a-2d2f56351cff

Runtime
.NET 6.0.5 (64-bit)
Architecture: Arm64

Roslyn (Language Service)
4.4.0-2.22419.1+ae5663806be933515723b2d5a85faf5d378f460d

NuGet
Version: 6.3.0.128

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.100-rc.1.22431.12/Sdks
SDK Versions:
7.0.100-rc.1.22431.12
6.0.401
6.0.400
6.0.400-preview.22330.6
MSBuild SDKs: /Applications/Visual Studio (Preview).app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET SDK (x64)
SDK Versions:
5.0.408
3.1.423
3.1.422
3.1.421

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
7.0.0-rc.1.22426.10
6.0.9
6.0.8
6.0.6

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
5.0.17
3.1.29
3.1.28
3.1.27

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode 14.0.1 (21336)
Build 14A400

Xamarin.Mac
Version: 8.12.0.2 (Visual Studio Community)
Hash: 87f98a75e
Branch: d17-3
Build date: 2022-07-25 20:18:54-0400

Xamarin.iOS
Version: 15.12.0.2 (Visual Studio Community)
Hash: 87f98a75e
Branch: d17-3
Build date: 2022-07-25 20:18:55-0400

Xamarin Designer
Version: 17.4.0.124
Hash: ffbba0c031
Branch: remotes/origin/d17-4
Build date: 2022-09-15 15:36:42 UTC

Xamarin.Android
Version: 13.0.99.81 (Visual Studio Community)
Commit: xamarin-android/main/7c9c24b
Android SDK: /Users/macminim1/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
12.0 (API level 31)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.2
SDK Build Tools Version: 33.0.0

Build Information:
Mono: dffa5ab
Java.Interop: xamarin/java.interop/main@2c8b0a8f
SQLite: xamarin/sqlite@40e8743
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@29f11f2

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.4.0.45
Hash: 8cac7ea
Branch: remotes/origin/HEAD~1
Build date: 2022-09-15 15:36:46 UTC

Android Device Manager
Version: 0.0.0.1196
Hash: b2faf27
Branch: main~1
Build date: 2022-09-15 15:36:46 UTC

Build Information
Release ID: 1704001583
Git revision: 70322329919c72a11d9795a3cb403fe4115a5878
Build date: 2022-09-15 15:34:40+00
Build branch: release-17.4
Build lane: release-17.4

Operating System
Mac OS X 12.5.0
Darwin 21.6.0 Darwin Kernel Version 21.6.0
Sat Jun 18 17:05:47 PDT 2022
root:xnu-8020.140.41~1/RELEASE_ARM64_T8101 arm64

Build Information
Release ID: 1704001583
Git revision: 70322329919c72a11d9795a3cb403fe4115a5878
Build date: 2022-09-15 15:34:40+00
Build branch: release-17.4
Build lane: release-17.4

Operating System
Mac OS X 12.5.0
Darwin 21.6.0 Darwin Kernel Version 21.6.0
Sat Jun 18 17:05:47 PDT 2022
root:xnu-8020.140.41~1/RELEASE_ARM64_T8101 arm64

  • Nuget Packages:
  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.9" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>

  <PackageReference Include="SQLitePCLRaw.core" Version="2.1.2" />
      <PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.2" />
      <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.2" />
      <PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.2" />
  <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.9" />
  <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
  <PackageReference Include="Radzen.Blazor" Version="4.1.0" />
  <PackageReference Include="Serilog.Sinks.Seq" Version="5.2.0" />
  <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
  <PackageReference Include="ZXing.Net.Maui" Version="0.1.0-preview.7" />
  <PackageReference Include="BlazorComponentBus" Version="2.1.0" />
  <PackageReference Include="Xamarin.CommunityToolkit.MauiCompat" Version="2.0.2-preview1013" />
  <PackageReference Include="Xamarin.CommunityToolkit.Markup.MauiCompat" Version="2.0.2-preview1013" />
</ItemGroup>
  • Affected Devices:

  • MAUI Version:
    Could not find it anywhere but I imagine it recent as this is a new install of Visual Studio Preview for Mac,

Workaround

None

@julianadormon julianadormon added bug Something isn't working. Breaky break. maui-compat labels Sep 29, 2022
@julianadormon
Copy link
Author

FYI, I also get the same error trying to debug on a physical Android device.

@bijington
Copy link
Contributor

I know we have discussed internally that things like CameraView would not be expected to work well if at all in MauiCompat due to complexities and limitations of the compat layer. I don't know if we ever came to a decision on how to make this publicly known - we did discuss marking as obsolete so warnings would present.

Sadly this isn't going to help solve this but I believe the answer is going to be to not use the CameraView in a MauiCompat based app. At least that is my understanding, hopefully someone else might rubbish my statement

@julianadormon
Copy link
Author

Thanks @bijington I was hoping that was not the case. I appreciate your insight.

@workgroupengineering
Copy link

workgroupengineering commented Nov 28, 2022

I have a similar issue with Xamarin.Form 5.0.0.2515 , Xamarin.CommunityToolkit 2.0.5

AndroidRuntime] java.lang.IllegalArgumentException: No view found for id 0x37 (unknown) for fragment CameraFragment{1d6a23a} (af9ca8f7-3e90-410f-9c47-5aa8d6db2ec7 id=0x37 tag=camera)
[AndroidRuntime] 	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
[AndroidRuntime] 	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
[AndroidRuntime] 	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
[AndroidRuntime] 	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
[AndroidRuntime] 	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
[AndroidRuntime] 	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
[AndroidRuntime] 	at android.os.Handler.handleCallback(Handler.java:938)
[AndroidRuntime] 	at android.os.Handler.dispatchMessage(Handler.java:99)
[AndroidRuntime] 	at android.os.Looper.loop(Looper.java:223)
[AndroidRuntime] 	at android.app.ActivityThread.main(ActivityThread.java:7656)
[AndroidRuntime] 	at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
[AndroidRuntime] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Edit: add simple project.
CameraViewIssue.zip

@bradencohen
Copy link

bradencohen commented Sep 7, 2023

I could be missing something, but it seems like this error prevents Android builds in Release mode:

1>ILLink : error IL8000: Could not find Android Resource '@layout/camerafragment'. Please update @(AndroidResource) to add the missing resource.
1>ILLink : error IL8000: Could not find Android Resource '@layout/camerafragment'. Please update @(AndroidResource) to add the missing resource.
1>ILLink : error IL8000: Could not find Android Resource '@layout/camerafragment'. Please update @(AndroidResource) to add the missing resource.
1>ILLink : error IL8000: Could not find Android Resource '@layout/camerafragment'. Please update @(AndroidResource) to add the missing resource.
1>C:\np\microsoft.net.illink.tasks\8.0.0-preview.7.23375.6\build\Microsoft.NET.ILLink.targets(84,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.
1>Done building project "Project.csproj" -- FAILED.

Will test disabling optimization, but I'm not sure that's a great final solution (shouldn't that be on?). I'm not using a CameraView anywhere in my application.

@dellis1972
Copy link

@bradencohen

The problem here is that this script

sed -i '' 's/MauiCompat.Resource.Layout.CameraFragment/MauiCompat.Resource.Layout.camerafragment/g' ./src/CommunityToolkit/Xamarin.CommunityToolkit.MauiCompat/**/CameraFragment.android.cs

is renaming the code to use all lowercase, but the actual Resource/Layout is still called CameraFragment.
This results in a .net/__res_name_case_map.txt being packaged in the .aar file which comes from the NuGet Package.
This contains a remap entry
Resources/Layout/CameraFragment.axml;layout/camerafragment.xml
which tells the Android build system to expect the code to use CameraFragment but the resource file is camerafragment. I'm not sure why the script was run on the code but it does seem to cause issues when upgrading
to .net8.0-android.

The fix is to modify your local Xamarin.CommunityToolkit.MauiCompat.aar file to remove the .net/__res_name_case_map.txt file (the aar is just a zip file you can modify). Alternatively someone could fix the casing of the CameraFragment.xml file in this repo to match the lowercase they want in the code. This would mean the remap file would not be needed. Finally I am working on a PR which will work around this problem in dotnet/android#8376. But in an ideal world this should not be needed. Having this mismatching code/resource file could cause all sorts of issues.

@bijington
Copy link
Contributor

I believe the CameraView implementation in the .NET MAUI Community Toolkit is very close now so it would probably be a better move to migrate to using that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working. Breaky break. maui-compat
Projects
None yet
Development

No branches or pull requests

5 participants