Android Question BiometricManager - Cannot find constructor - SOLVED!

artsoft

Active Member
Licensed User
Longtime User
Hi!

After update to version 12, I get this now:

B4X:
Error occurred on line: 59 (BiometricManager)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7750)
    at android.view.View.performClickInternal(View.java:7727)
    at android.view.View.access$3700(View.java:858)
    at android.view.View$PerformClick.run(View.java:29115)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:210)
    at android.os.Looper.loop(Looper.java:299)
    at android.app.ActivityThread.main(ActivityThread.java:8168)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)

I am using the BiometricManager from @Erel - version 1.0.0

This row throws an exception:

B4X:
Prompt.InitializeNewInstance("androidx.biometric.BiometricPrompt", Array(ctxt, Executor, Ev))

My Main includes this:

B4X:
#AdditionalJar: androidx.biometric:biometric
#AdditionalJar: androidx.arch.core:core-runtime
#MultiDex: True

The AppCompat is also referenced:

1669114157247.png


What is wrong here?
What I need now?

Thankful for any help.

Regards
ARTsoft
 
Last edited:

artsoft

Active Member
Licensed User
Longtime User
Update:

I tried to include AppCompat.v7 by using this...

B4X:
#Extends: android.support.v7.app.AppCompatActivity

... and using an AppCompat theme: Theme.AppCompat.NoActionBar

But no effect... Same error!

Do I need a new BiometricsManager that calls a correct Java constructor?

BTW - Biometrics lib is also installed:

1669115272517.png


Thanks and regards
ARTsoft
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried to include AppCompat.v7 by using this...
100% wrong! android.support.v7 is deprecated since YEARS now.

NO NEED to install anything with the SDK-Manager

Check the appcompat library in the library tab should be enough.
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
100% wrong! android.support.v7 is deprecated since YEARS now.

NO NEED to install anything with the SDK-Manager

Check the appcompat library in the library tab should be enough.

Hi - thanks for your answer.
Yes, appcompat.v7 is old - you are right.

The references to this lib are deleted.
Unfortunately the Biometrics example of Erel also uses this lib.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
see above comment of @DonManfred - deprecated.
B4A usually uses the correct androidx replacement for it.
At least in the past this was the case if i remember correctly.

But as you say the example https://www.b4x.com/android/forum/threads/biometricmanager-biometric-authentication.111256/ does raise the same error then i guess there must be something special now and maybe something need to get aligned.

Edit: I tried the example (as-is) and it does not give any Error.
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
B4A usually uses the correct androidx replacement for it.
At least in the past this was the case if i remember correctly.

But as you say the example https://www.b4x.com/android/forum/threads/biometricmanager-biometric-authentication.111256/ does raise the same error then i guess there must be something special now and maybe something need to get aligned.

Edit: I tried the example (as-is) and it does not give any Error.

Hm.... ?

Again:

These entries are currently used to include other libs (in Main):

B4X:
#AdditionalJar: androidx.biometric:biometric
#Extends: androidx.appcompat.app.AppCompatActivity
#AdditionalJar: androidx.arch.core:core-runtime
#MultiDex: True

This is also attached (because I need this theme: <style name="MyAppTheme" parent="Theme.AppCompat.NoActionBar">

1669118826452.png


This is the relevant part of my manifest:

B4X:
AddPermission (android.permission.USE_BIOMETRIC)
AddPermission (android.permission.USE_FINGERPRINT)

CreateResource (
    drawable,
    mygradient.xml,
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <gradient android:angle="90" android:startColor="#FF000000" android:endColor="#FFFF0000" android:type="linear"/>
    </shape>
)

SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
        <resources>
            <style name="MyAppTheme" parent="Theme.AppCompat.NoActionBar">
                <item name="android:windowBackground">@drawable/mygradient</item>
            </style>
        </resources>
)

I am using these setting since many months.

But I get always this:

B4X:
biometricmanager_show (java line: 188)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7750)
    at android.view.View.performClickInternal(View.java:7727)
    at android.view.View.access$3700(View.java:858)
    at android.view.View$PerformClick.run(View.java:29115)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:210)
    at android.os.Looper.loop(Looper.java:299)
    at android.app.ActivityThread.main(ActivityThread.java:8168)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)

And in the generated java code, this line throws an exception:

1669119525439.png


What could it be???

Regards
 
Last edited:
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
* * * OMG - sometime I am very stupid!!!!!! * * *

The exception thrown in my app (described above) - regarding the biometric java constructor - was really my mistake!!!

I thought that it is absolutely enough to include the AppCompat in the Main activity, but I know now that I have to insert this extension command ...

B4X:
#Extends: androidx.appcompat.app.AppCompatActivity

... in each activity which is using the biometric feature.

So in my case, there was a need to insert this "extension directive" in 4 activities of my app.

Final result: No exception anymore regarding biometrics.

So now, we can close this thread.

I have to say THANK YOU to all helpers here.

Best regards
ARTsoft
 
Upvote 0
Top