Search code examples
androidfacebookionic-frameworkbarcode-scanner

ionic facebook and barcodescanner issue


I have a problem with facebook plugin and barcode scanner, first i created a projects separate to check how facebook plugin work and was working perfect, but when I added the facebook plugin to my project where im using barcodescanner plugin i cant run the project in android, I got the following exception:

 BUILD FAILED

Total time: 10.111 secs
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

[ERROR] An error occurred while running cordova run android (exit code 1).

Solution

  • Step 1 : Install Barcode Scanner Plugin:

    $ ionic cordova plugin add phonegap-plugin-barcodescanner
    $ npm install --save @ionic-native/barcode-scanner
    

    Step 2: Install Facebook plugin: (Use the below facebook plugin version)

    ionic cordova plugin add cordova-plugin-facebook4@1.7.4 --variable APP_ID="****" --variable APP_NAME="****"
    npm install --save @ionic-native/facebook
    

    Step 3: Open the file facebookconnect.xml from this path : yourapp\platforms\android\app\src\main\res\values and add two lines inside <resources></resources>

    <resources>
      <string name="fb_app_id">***your_app_id***</string>
      <string name="fb_app_name">***your_app_name***</string>
    </resources>
    

    Step 4: Command : cordova clean - allow cordova clean your app

    Step 5: Command : cordova build - check cordova build your app

    Step 6: Command : ionic cordova build android - Build your app