BlinkID / blinkid-cordova

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

usdlCombinedRecognizer crash #84

Closed AlibekJ closed 5 years ago

AlibekJ commented 5 years ago

The following code crashes on Android

var usdlCombinedRecognizer = new cordova.plugins.BlinkID.UsdlCombinedRecognizer();
var documentOverlaySettings = new cordova.plugins.BlinkID.DocumentVerificationOverlaySettings();
var recognizerCollection = new cordova.plugins.BlinkID.RecognizerCollection([usdlCombinedRecognizer]);

scanButton.addEventListener('click', function () {
  cordova.plugins.BlinkID.scanWithCamera(
    function callback(cancelled) {},
    function errorHandler(err) {},
    documentOverlaySettings, recognizerCollection, licenseKeys
  );
});

logcat:

09-26 16:40:43.102 9797 9797 E AndroidRuntime: FATAL EXCEPTION: main 09-26 16:40:43.102 9797 9797 E AndroidRuntime: Process: com.acme.blink, PID: 9797 09-26 16:40:43.102 9797 9797 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acme.blink/com.microblink.activity.DocumentVerificationActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2720) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.ActivityThread.-wrap12(ActivityThread.java) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.os.Looper.loop(Looper.java:241) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6274) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.initWindowDecorActionBar(AppCompatDelegateImplV9.java:175) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:145) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.support.v7.app.AppCompatActivity.getSupportActionBar(AppCompatActivity.java:109) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at com.microblink.activity.DocumentVerificationActivity.onCreate(line:43) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6720) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 09-26 16:40:43.102 9797 9797 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2673)

Any ideas?

culoi commented 5 years ago

Hello @AlibekJ ,

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

Please edit AndroidManifest.xml and set theme to Theme.AppCompat

Which version of the Cordova are you using?

Regards

culoi commented 5 years ago

Sorry, please use: Theme.AppCompat.NoActionBar

With this theme you will get the following:

theme_appcompat_noactionbar

Regards

AlibekJ commented 5 years ago

I am on cordova 8.1..0

Please edit AndroidManifest.xml and set theme to Theme.AppCompat

Sorry, culoi, would you, please, be more specific. I found 14 AndroidManifest.xml files, modified the one in /platforms/android/CordovaLib like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.apache.cordova" android:versionName="1.0" android:versionCode="1" android:theme="@android:style/Theme.AppCompat.NoActionBar">
    <uses-sdk android:minSdkVersion="16" />
</manifest>

and it had no effect. I am not sure what I am doing.

willuhn commented 5 years ago

I had exactly the same problem. Took me about a week to find out: It's the "DocumentVerificationOverlaySettings". Use "DocumentOverlaySettings" instead.

I've no idea, what the difference is, but it doesn't crash anymore. The demo code also uses "DocumentOverlaySettings": https://github.com/BlinkID/blinkid-phonegap/blob/master/www/js/index.js#L78

culoi commented 5 years ago

If you are using CombinedRecognizer, documentVerificationOverlay is must, as it notifiy the user to scan the front and the back side.

Please check it our more here: https://github.com/BlinkID/blinkid-android#-documentverificationactivity-and-documentverificationoverlaycontroller

You can also check out our video of implementing verificationOverlay and UsdlCombined recognizer: https://github.com/BlinkID/blinkid-phonegap#using-documentverificationoverlay-and-combinedrecognizer

Regards

culoi commented 5 years ago

Hello @AlibekJ

Location of the AndroidManifex.xml is as following:

/platforms/android/app/src/main/

Please test it out and let us know how it works.

Regards

AlibekJ commented 5 years ago

Tried your suggestion, modified /platforms/android/app/src/main/AndroidManifest.xml

However, when trying to build, script adds another line into AndroidManifest.xml like this:

<activity android:configChanges="orientation|screenSize" android:name="com.microblink.activity.ScanCard" android:screenOrientation="portrait" android:theme="@android:style/Theme.AppCompat.NoActionBar" />
<activity android:configChanges="orientation|screenSize" android:name="com.microblink.activity.ScanCard" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

so naturally it fails with:

Element activity#com.microblink.activity.ScanCard at AndroidManifest.xml:13:9-212 duplicated with element declared at AndroidManifest.xml:12:9-212

i1E commented 5 years ago

Hi @AlibekJ,

you have to modify the AndroidManifest.xml inside the demo application that is created with initCordovaDemoApp.sh script (after this scrip is executed), or AndroidManifest.xml inside your application if you don't use initCordovaDemoApp.sh.

In the next release of the BlinkID cordova plugin, this will be fixed and you won't need to do any modifications to make things work.

Best Regards

cameronwiebe commented 5 years ago

I am having this same issue on iOS. When using the same code as @AlibekJ above, I receive the following error:

-[NSNull length]: unrecognized selector sent to instance 0x1b4c7f878

Reverting to var documentOverlaySettings = new cordova.plugins.BlinkID.DocumentOverlaySettings(); fixes the error but does not allow me to scan both the front and back of the ID. Thoughts?

AlibekJ commented 5 years ago

Suggestion one above given by @i1E worked for me.

cameronwiebe commented 5 years ago

Suggestion one above given by @i1E worked for me.

Thanks for the response! I am only interested in getting this working on iOS at the moment. It seems the solution above is addressing android builds. Is there something similar I need to do to get this going on iOS?

AlibekJ commented 5 years ago

Try this. I just ran it on iOS and it worked.

  let usdlCombinedRecognizer = new cordova.plugins.BlinkID.UsdlCombinedRecognizer();
  usdlCombinedRecognizer.returnFaceImage = true;
  usdlCombinedRecognizer.returnFullDocumentImage = true;
  let documentOverlaySettings = new cordova.plugins.BlinkID.DocumentVerificationOverlaySettings();
  let usdlSuccessFrameGrabber = new cordova.plugins.BlinkID.SuccessFrameGrabberRecognizer(usdlCombinedRecognizer);
  let recognizerCollection = new cordova.plugins.BlinkID.RecognizerCollection([usdlSuccessFrameGrabber]);

  myfunction = function () {
    cordova.plugins.BlinkID.scanWithCamera(
      function callback(cancelled) {
        if (usdlCombinedRecognizer.result.resultState == cordova.plugins.BlinkID.RecognizerResultState.valid) {

        }
      },
      function errorHandler(err) {},
      documentOverlaySettings, recognizerCollection, licenseKeys
    );
  };
jcular commented 5 years ago

Hi @cameronwiebe,

can you try setting the property values on DocumentVerificationOverlaySettings to following values and not to null?

glareMessage = "Slightly move ID to eliminate glare.";
firstSideInstructions = "Place the front side of the document in the frame and wait for automatic scan.";
secondSideInstructions = "Place the back side of the document in the frame and wait for automatic scan.";
firstSideSplashMessage = "Document front side";
secondSideSplashMessage = "Document back side";
scanningDoneSplashMessage = "Document scanning done";
cameronwiebe commented 5 years ago

@jcular This solved it! Thanks so much for the help.