Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
461 stars 151 forks source link

Not possible use on a MAUI class Library, not available...? #103

Open JORGEGO opened 1 year ago

JORGEGO commented 1 year ago

Works correct on a MAUI mobile project, but if you try to use on a MAUI class project Screenshot 2023-01-18 225514

zh-95 commented 1 year ago

Hi i'm having the same issue... I've worked with thi lib with no problem in the maui app, but now when i'm trying to create a custom component in a maui class library it's looks like it can't be able to finde packages Did u solve it in some way?

JORGEGO commented 1 year ago

Well, my workaround is move the code to a not class library project, then works well.

aalivingston commented 1 year ago

I ran into this issue as well. The problem is that you can't build ZXing.Net.Maui again net7.0, it only supports the platform-specific frameworks. However, many class libraries need to be buildable against net7.0 for automated testing purposes.

I solved this by making ZXing.Net.Maui a conditional package reference in my library's csproj that only loads for Android and iOS targeted builds. Then, I wrote a wrapper class for CameraBarcodeReaderView that isolated all of the ZXing.Net.Maui components from the rest of my class library. Finally, I used preprocessor directives for ANDROID and IOS to hide all ZXing library code within my wrapper class when building against net7.0. Problem solved.

Plus, it's just good practice to wrap 3rd party dependencies in interfaces that you control. It gives the you the flexibility to update/change how you consume those libraries without affecting the design of the rest of your application.