BlinkID / blinkid-android

Everything you need to add AI-driven ID scanning into your native Android app.
https://microblink.com/identity/identity-document-scanning/
445 stars 153 forks source link

NullPointerException in scan BlinkIdActivity #253

Closed HosseinDevPro closed 1 year ago

HosseinDevPro commented 3 years ago

Description

We got a null pointer exception when scanning an id card. When the app goes in the background with low memory(that cause killing activity) and returns back to scan activity getting this: 'java.io.File android.content.Context.getFilesDir()' on a null object reference

Environment Details

BlinkID version:5.12

Device model:A3 2016

Device Android version: 7.0

Device ABI (processor architecture, e.g. ARMv7): ArmV8

Log file

Stack trace: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hkh.gggg.dev/com.microblink.activity.BlinkIdActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6776) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference at com.microblink.intent.IlIllIlIIl.llIIlIlIIl(line:25) at com.microblink.intent.IllIIIllII.llIIlIlIIl(line:49) at com.microblink.intent.llIIlIlIIl.loadFromIntent(line:8) at com.microblink.uisettings.BaseBlinkIdUiSettings.<init>(line:5) at com.microblink.uisettings.BlinkIdUISettings.<init>(line:2) at com.microblink.activity.BlinkIdActivity.llIIlIlIIl(line:1) at com.microblink.activity.BaseScanActivity.onCreate(line:1) at android.app.Activity.performCreate(Activity.java:6955) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927) ... 9 more

anjapenic commented 3 years ago

Hi @hossein114,

Would you mind sharing how are you setting the license key? Did you follow the steps described here (https://github.com/BlinkID/blinkid-android#performing-your-first-scan) and set the license key before using any other classes from the SDK?

Regards, Anja

anjapenic commented 3 years ago

Hi @hossein114,

Just wanted to make a follow-up here and check if you're still experiencing the crash?

Best regards,

Anja

HosseinDevPro commented 3 years ago

Hi Yes, this crash still report to us in some devices . Many thanks for your follow-up. Best regards

On Thu, Sep 9, 2021, 18:11 anjapenic @.***> wrote:

Hi @hossein114 https://github.com/hossein114,

Just wanted to make a follow-up here and check if you're still experiencing the crash?

Best regards,

Anja

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BlinkID/blinkid-android/issues/253#issuecomment-916109024, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7KT6CHDEIXXGYCTA5RSWLUBC2QNANCNFSM5CUMEBEQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

anjapenic commented 3 years ago

Hi @hossein114,

Is the crash occurring only in the Galaxy A3 2016 devices you've mentioned in the first post or are there crashes in other devices as well?

Best regards, Anja

HosseinDevPro commented 3 years ago

Hi We have this crash in some other devices also . We receive this crash in Countly crash report panel. I produce this crash in A3 2016. Thanks .

On Tue, Sep 14, 2021, 13:25 anjapenic @.***> wrote:

Hi @hossein114 https://github.com/hossein114,

Is the crash occurring only in the Galaxy A3 2016 devices you've mentioned in the first post or are there crashes in other devices as well?

Best regards, Anja

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BlinkID/blinkid-android/issues/253#issuecomment-918951762, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7KT6EEFBDCRRNWEN5EWPLUB4EXVANCNFSM5CUMEBEQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

anjapenic commented 3 years ago

Hi @hossein114,

Could you share with us how are you setting the license key? Did you follow the steps described here (https://github.com/BlinkID/blinkid-android#performing-your-first-scan) and set the license key before using any other classes from the SDK?

Also, which other devices are you experiencing crashes on?

Best regards, Anja

HosseinDevPro commented 3 years ago

Many thanks for your reply. At first need to say that we have this issue in some devices, so license setup is correctly done. As you can see the crash report, this issue was happens on memry access and it got a null pointer exception. As your source code was obfuscated we can't debug any more . Thanks .

On Thu, Sep 16, 2021, 19:47 anjapenic @.***> wrote:

Hi @hossein114 https://github.com/hossein114,

Could you share with us how are you setting the license key? Did you follow the steps described here ( https://github.com/BlinkID/blinkid-android#performing-your-first-scan) and set the license key before using any other classes from the SDK?

Also, which other devices are you experiencing crashes on?

Best regards, Anja

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BlinkID/blinkid-android/issues/253#issuecomment-920995563, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7KT6CR2H74MINRQIERGL3UCIDBNANCNFSM5CUMEBEQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

anjapenic commented 3 years ago

Hello @hossein114,

We have checked in our code and this exception is thrown only if the license key has not been set before starting the scan activity. Error message should be better for that case and we will fix that.

So let me explain better what is happening here.

Suppose you set the license key in the application class. In that case, like described here, you can be sure that the license key is always set before using any method from our SDK, because Application.onCreate() is always called on application startup.

If you set the license key in some method that is not called before the scan activity is being launched, you will get this exception. And this will not always happen, only in some situations. For example, when the user is on the scan activity and switches to another application, OS can decide to kill the scanning application to free up the resources. When the user navigates back to the scanning application, scan activity will be on top. If you didn't ensure that the license key is set (for example, if you set the license key on some button click which is not performed in this situation), you would get this exception. If you want to reproduce this issue, you can force the OS to immediately destroy the application process when you leave the application, in developer options under "Background process limit" choose option "No background processes".

Best regards, Anja

HosseinDevPro commented 3 years ago

Hi @anjapenic As you say, an error message of the exception in the context of getFilesDir is very confusing. Ok, we will do as you say and check the future result on the user's phone. Many thanks.

anjapenic commented 3 years ago

Hello @hossein114,

Agreed, we'll fix the error message so it's more clear what's causing the crash. Keep us updated on your progress and if you need any further assistance, feel free to ask.

Best regards, Anja

HosseinDevPro commented 3 years ago

@anjapenic In our project, we get the licence key from the server, so we cant to set the licence in the application class. Can you fix this issue in the library source? when the user set the licence at first, don't need to set it again so the crash not occurred. Thanks.

anjapenic commented 3 years ago

Hi @hossein114,

Unfortunately, we cannot do anything about that in the SDK. It is technically not possible without introducing security problems. When the application is killed and recreated, it is opened again in an entirely different process, which does not communicate with the previous process where the license key was set.

The best option is to set the license key in the application class. There is another option for you, to bypass this issue, you can set noHistory option for the BlinkIdActivity in your AndroidManifest.xml.

<activity
android:name="com.microblink.activity.BlinkIdActivity"
android:noHistory="true"/>

Here is the documentation for noHistory option: https://developer.android.com/guide/topics/manifest/activity-element#nohist.

If you enable it, activity will not remain in the activity stack for the task, when the user leaves the application. This means that when the user returns to the application, BlinkIdActivity will not be on top and will not be recreated. But this also will affect normal usage because the activity will be finished as soon as the user navigates away from it and it's no longer visible on screen.

Regards, Anja

krizaa commented 1 year ago

This issue was closed because it has been inactive for such a long time. If the issue persists, please open a new one.