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

plugin appears incompatible with phonegap-plugin-barcodescanner on Android (ZXing) #83

Closed
viking2917 opened this issue Aug 24, 2021 · 5 comments

Comments

@viking2917
Copy link

Bug or feature request

[ X] I'm reporting a reproducible issue with the code
[ ] I'm reporting a feature request

Describe the Bug or feature request

cordova-plugin-facebook-connect appears to be incompatible with phonegap-plugin-barcodescanner on Android. Creating an ionic v1 project, and installing both plugins will result in a compile error of the form:

> Task :app:checkDebugDuplicateClasses FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class com.google.zxing.BarcodeFormat found in modules jetified-barcodescanner-release-2.1.5-runtime.jar (:barcodescanner-release-2.1.5:) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
  Duplicate class com.google.zxing.Binarizer found in modules jetified-barcodescanner-release-2.1.5-runtime.jar (:barcodescanner-release-2.1.5:) and jetified-core-3.3.3.jar (com.google.zxing:core:3.3.3)
...etc for many lines....

Expected Behavior

Ideally these plugins would co-exist. As with the precursor plugin, cordova-plugin-facebook4, they are incompatible as they both include the zxing libraries, which results in a duplicate class error. (see below).

Sample repo / To Reproduce

Create a sample ionic v1 project, e.g.:

ionic start myApp tabs --type ionic1

then:

ionic cordova plugin add phonegap-plugin-barcodescanner
ionic cordova plugin add cordova-plugin-facebook-connect --save --variable APP_ID="<appid>" --variable APP_NAME="appname"

and then build on Android, the error will occur.

Plugin version, OS, devices, etc

Problem occurs with latest version of plugin, and on Android only.

Additional Context

The issues with cordova-plugin-facebook4 are documented here: (phonegap/phonegap-plugin-barcodescanner#606, phonegap/phonegap-plugin-barcodescanner#535) and a workaround is described, involving creating a build instruction to not include the zxing libraries for the facebook plugin. I have created a fork of this plugin (cordova-plugin-facebook-connect) that implements these changes, and it compiles and works fine on both Android and iOS so far as I can tell, in case it is helpful to someone (https://github.com/viking2917/cordova-plugin-facebook-connect).

However I wonder if there is a way this can be accomplished using the official plugins without forking them?

@noahcooper
Copy link

noahcooper commented Aug 26, 2021

My initial reaction is that it would make the most sense for someone to fork phonegap-plugin-barcodescanner and update it to address this issue. At some point, that plugin is going to have to be forked and updated -- like all Phonegap plugins it is no longer maintained. The solution would be to:

a) Get rid of the local version of com.google.zxing and instead use Maven
b) Add a preference for developers to specify the version at runtime, e.g. --variable ZXING_VERSION="3.3.1"

I don't think it makes sense for this plugin to try to fiddle with the Facebook SDK's internal dependencies, which could have unexpected results. Doing so would also require changing the way that the Facebook SDK is included to use build.gradle and a hook instead of specifying the dependency in plugin.xml, which adds unnecessary overhead for people not using the barcode scanner plugin.

@viking2917
Copy link
Author

Hi @noahcooper, thanks for the response and for creating and maintaining this plugin to begin with!

I understand the reluctance to deal with this inside this plugin, makes sense. (and, I don't actually know why Facebook includes ZXing (the barcode scanner library for Android) in the first place). I'm an Android dev novice, I was hoping there might be a configuration trick to do this without forking either plugin, but sounds like there probably is not such a way.

Excluding the ZXing library from the barcode scanner is probably the most practical solution in the long run, as the barcode scanner plugin isn't likely to change much (although it's a bit weird to be excluding the ZXing library from the barcode scanner plugin as it is the primary consumer :) ). This plugin likely needs to change more over time as Facebook Connect seems to need constant tending based on Facebook changes, so the fork I created of this plugin is going to create more maintenance/merge issues down the road for me. (I'm currently using that fork I created in production, it does seem to work ok).

I may take a crack at forking the barcode scanner plugin at some point -- thanks for the suggested approach. There are some HTML5-based barcode scanning codes out there, which might be a more modern way of doing this in the first place, vs a plugin that hasn't been updated in years :)

Thanks again! I'm going to close this issue based on your feedback.

@noahcooper
Copy link

@viking2917 I did some analysis, and it looks like Facebook uses ZXing for only one thing -- device requests (i.e. when someone logs in from a device without a keyboard like a TV). Who knows if that will change though -- I wouldn't be surprised as they incorporate more features for Instagram and Messenger into the SDK if some new QR code scanning feature was added.

Good point about the fact that an HTML5-based solution might be better for some use cases. FWIW - creating a fork of the barcode scanner plugin wouldn't require excluding ZXing from its dependencies. The problem is simply that it uses a different version of the library, and, that it uses hardcoded jar files (see https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/src/android/barcodescanner-release-2.1.5.aar). If it instead used Maven, and allowed the version to be specified at runtime, it could then co-exist with plugins like this one. This is a common paradigm with other plugins, e.g. see how cordova-plugin-firebase-analytics allows developers to specify the version of Firebase Analytics to avoid the same kind of conflict.

@viking2917
Copy link
Author

@noahcooper Oh that's super helpful. I did not understand that (exclude vs let Maven pick). When I get some cycles I'm going to try out the Maven approach. And a facepalm to me for forgetting about the device signin with QRcodes :).

@pcsantana
Copy link

Hi!
You could resolve this issue with this approach:

jeduan#777 (comment)

No fork or changes in the original plugins code needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants