BlinkID / blinkid-cordova

ID scanning for cross-platform apps built with Cordova and Phonegap.
48 stars 34 forks source link

Conflict with cordova-plugin-qrscanner #82

Closed AlibekJ closed 5 years ago

AlibekJ commented 5 years ago

Here is how to reproduce the error:

cordova create blink com.acme.blink blink
cd blink
cordova platform add android
cordova plugin add cordova-plugin-qrscanner
cordova plugin add blinkid-cordova
cordova run android

And it fails with

Element uses-permission#android.permission.CAMERA at AndroidManifest.xml:21:5-65 duplicated with element declared at AndroidManifest.xml:15:5-90 /home/....../platforms/android/app/src/main/AndroidManifest.xml:23:5-60 Error: Element uses-feature#android.hardware.camera at AndroidManifest.xml:23:5-60 duplicated with element declared at AndroidManifest.xml:16:5-85 /home/......../platforms/android/app/src/main/AndroidManifest.xml Error: Validation failed, exiting

i1E commented 5 years ago

Hi @AlibekJ,

this is a bug in Cordova, problem is not in the blinkid-phonegap plugin nor cordova-plugin-qrscanner. But you can take a look at this issue, maybe you can find a workaround.

AlibekJ commented 5 years ago

Thanks for the link. I understand it is not your bug, but it is still a major issue which makes your product unusable. Would be great if you could spend some time to find the solution and provide detailed how-to document.

SandraZiv commented 5 years ago

Hi,

Both of the plugins you want to use in your project have the same camera permission where one specifically requires it and other don't, therefore Cordova will generate AndroidManifest.xml with conflicting permissions. Since the bug is in Cordova, we can only suggest you the following workaround.

After creating new cordova project, firstly add blinkid plugin. When plugin is successfully added, open plugins/com.microblink.BlinkIDScanner/plugin.xml and comment lines that are causing problem:

<uses-permission android:name="android.permission.CAMERA" ></uses>
<uses-feature android:name="android.hardware.camera" ></uses>

Now, you can add qrscanner plugin and android platform. The reason why the blinkid plugin was added before the android platform is so we can modify plugin.xml file so it doesn't generate duplicate lines in AndroidManifest.xml.

If you try to run your app now, you will get error saying:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

This error occurs because there are 2 versions of support libraries, qrscanner uses com.android.support:support-v4:23.1.0 and other dependencies have 27.1.1 version. To fix that, simply create build-extras.gradle in platforms/android/app with newer library version:

dependencies {
    implementation 'com.android.support:support-v4:27.1.1'
}

Finally, you just need to clean the project (cordova clean) and run the app (cordova run android) and it should work.

Best regards, Sandra

AlibekJ commented 5 years ago

yay, worked fine. Thank you very much, Sandra.