skip to Main Content

I am using ionic 4. When my project have facebook plugin and BarcodeScanner plugin and type ionic cordova run android, it will come out this error:

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.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D8: Program type already present: com.google.zxing.BarcodeFormat

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
  Program type already present: com.google.zxing.BarcodeFormat
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

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

I download both plugin using these command:

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

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

4

Answers


  1. This might be a dependency issue.

    If a class appears more than once on the runtime classpath, you get an error similar to the following:

    Program type already present com.example.MyClass

    This error typically occurs due to one of the following circumstances:

    A binary dependency includes a library that your app also includes as a direct dependency.

    For example, your app declares a direct dependency on Library A and Library B, but Library A already includes Library B in its binary. To resolve this issue, remove Library B as a direct dependency.

    Your app has a local binary dependency and a remote binary dependency on the same library.

    To resolve this issue, remove one of the binary dependencies, delete the redundant one. ( See if same library is added as a dependency)

    Follow this link for more details – Here

    Login or Signup to reply.
  2. From looking at the repo it doesn’t seem very active and somebody else opened an issue for this back in July with no acknowledgement.

    I guess at this point you need to ask yourself if you are in the mood to battle build errors for an unsupported plugin, or if you just want the feature to work, because there are other libraries that will do this for you.

    For example:

    You will need to double check it scans the exact barcode you are looking for but they support more than just the basic QR code, and hopefully don’t have the conflict with other plugins.

    Update – I just took a second look at this today and if you do want to battle it then you might be able to resolve the build issues using techniques in this answer.

    Login or Signup to reply.
  3. After weeks of searching, the following steps help me resolve the issue like a charm:

    1.Remove android platform.

    2.Install cordova-plugin-facebook4

    3.Create build.gradle in /plugins/cordova-plugin-facebook4/

    4.Copy

    dependencies { compile("com.facebook.android:facebook-android-sdk:4.37.0") { exclude group: 'com.google.zxing' } }
    

    to ../plugins/cordova-plugin-facebook4/build.gradle

    5.Edit ../plugins/cordova-plugin-facebook4/plugins.xml change

    <framework src="com.facebook.android:facebook-android-sdk:$FACEBOOK_ANDROID_SDK_VERSION"/>
    

    to

    <framework src="build.gradle" custom="true" type="gradleReference"/>
    

    6.Add android platform and build

    Login or Signup to reply.
  4. Well, I found a solution that works for me, using barcodescanner and facebook4

    1. go to the folder plugins/cordova-plugin-facebook4

    2. create a file "build.gradle" and add these lines

       dependencies {compile("com.facebook.android:facebook-android-sdk:4.37.0") {exclude group:'com.google.zxing'}}
      
    3. Open the file plugins/cordova-plugin-facebook4/plugin.xml and replace the line:

       <framework src="com.facebook.android:facebook-android-sdk:$FACEBOOK_ANDROID_SDK_VERSION"/>
      

      to

       <framework src="build.gradle" custom="true" type="gradleReference"/>
      
    4. remove and add the android platform using these commands in the path of your app

       ionic cordova platform rm android
      
       ionic cordova platform add android
      
    5. finally build your application

       ionic cordova build android
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search