Android Question biometric library error

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Using the lib and example of : https://www.b4x.com/android/forum/threads/biometricmanager-biometric-authentication.111256/
b4a 10.7 install from scratch, last SKD and so on...
Running on a S7
Pressing the Authenticate button...
Im getting the following error
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NoSuchFieldError: No static field colorError of type I in class Landroidx/biometric/R$attr; or its superclasses (declaration of 'androidx.biometric.R$attr' appears in /data/app/b4a.example-Yv-9jn5OKLdjKgxHNQKoKw==/base.apk)
at androidx.biometric.FingerprintDialogFragment$Api26Impl.getColorErrorAttr(FingerprintDialogFragment.java:440)
at androidx.biometric.FingerprintDialogFragment.onCreate(FingerprintDialogFragment.java:161)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2685)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2181)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2004)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1959)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

How to solve this?
Thanks
 

LucaMs

Expert
Licensed User
Longtime User
You don't need 29.
1618839035093.png
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I can confirm that with the last changes it works on Android 8.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
even trying with jdk11, jdk14, jdk8
It is not related to Java. It also not really related to this thread. This error happens when the zip wasn't unzipped properly. Delete the SDK folder and do it again.

There is no relation between android.jar and targetSdkVersion.
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
OK, the example work ok , now I take my app, modify the manifest, add the class, compile with the code but wothout authenticating and it compiles and run ok.
When I add the lines to authenticate...
B4X:
    bm.Initialize(Me, "Authenticate")
    Dim res As String = bm.CanAuthenticate
    If res = "SUCCESS" Then
        LogColor("Biometric OK",Colors.Blue)
        Main.Biometric = True
    Else
        LogColor("Biometric not available",Colors.Blue)
        Main.Biometric = False
    End If
    
    If FirstTime = True Then
        If Main.ChekearConHuella=True And Main.Biometric = True Then 'si esta el check en ajustes
            LogColor("va a autenticar...",Colors.Blue)
            bm.Show("Autentíquese...")
            Wait For Authenticate_Complete (Success As Boolean, ErrorMessage As String)
            If Success=False Then
                Alerter1.Title("Bienvenido!")
                Alerter1.Text("Autenticación inválida.")
                Alerter1.BackgroundColor(Colors.Green)
                Alerter1.Show
                ExitApplication
            End If
        End If
        SQL1.Initialize(File.DirInternal, "portit.db", False)
    End If

I got this error:
B4X:
Biometric OK
va a autenticar...
biometricclass_show (java line: 170)
java.lang.ClassNotFoundException: armi$portit$biometricmanager$BiometricPromptAuthentication
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
    at armi.portit.biometricclass._show(biometricclass.java:170)
    at armi.portit.mdashboard$ResumableSub_Activity_Create.resume(mdashboard.java:558)
    at armi.portit.mdashboard._activity_create(mdashboard.java:432)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at armi.portit.mdashboard.afterFirstLayout(mdashboard.java:105)
    at armi.portit.mdashboard.access$000(mdashboard.java:17)
    at armi.portit.mdashboard$WaitForLayout.run(mdashboard.java:83)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
biometricclass_show (java line: 170)
java.lang.ClassNotFoundException: armi$portit$biometricmanager$BiometricPromptAuthentication
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Sory I did not think this was important. Ive delete it and add it again and now:
B4X:
Biometric OK
va a autenticar...
biometricmanager_show (java line: 174)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at armi.portit.biometricmanager._show(biometricmanager.java:174)
    at armi.portit.mdashboard$ResumableSub_Activity_Create.resume(mdashboard.java:571)
    at armi.portit.mdashboard._activity_create(mdashboard.java:432)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at armi.portit.mdashboard.afterFirstLayout(mdashboard.java:105)
    at armi.portit.mdashboard.access$000(mdashboard.java:17)
    at armi.portit.mdashboard$WaitForLayout.run(mdashboard.java:83)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
biometricmanager_show (java line: 174)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at armi.portit.biometricmanager._show(biometricmanager.java:174)
    at armi.portit.mdashboard$ResumableSub_Activity_Create.resume(mdashboard.java:571)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This error happens when the zip wasn't unzipped properly
This error will be resolved if you unzip it with 7zip.
I have only 7zip!
Mea culpa, mea culpa, mea maxima culpa ?

I have only 7zip... as "additional" tool, but I had unzipped it "automatically" with "Extract all" menu (contextual menu), then with the Windows internal tool.

Now all works (Android 8).
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hiya @Erel
After editing your original code example with the following code, the touch ID and Face Unlock features are now working on all of my devices that have those features, that include Samsung, Google and Huawei.

It seems like a bug or a new dependency in the latest version of AndroidX.
The activity must be an AppCompat activity:
1. Main:
B4X:
#AdditionalJar: androidx.biometric:biometric
#Extends: android.support.v7.app.AppCompatActivity
#AdditionalJar: androidx.arch.core:core-runtime
#AdditionalJar: androidx.appcompat:appcompat
2. Manifest:
B4X:
AddPermission(android.permission.USE_BIOMETRIC)
AddPermission(android.permission.USE_FINGERPRINT)
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light">
    </style>
</resources>
)

Tested on Android 8 and 11.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
AppCompat is indeed less recommended with B4XPages. I will post a B4XPages example.
Thanks to your update of B4XPages to v. 1.09, it works even with B4XPages (I don't have B4I so I just "created" the B4A version. "created"? Only a few copy and paste were needed :). Great!)



[I know, you updated B4XPage for this reason or, better, for this type of need, AppCompat... B4XpagesCompatibility :) ]
 

Attachments

  • BiometricManager.zip
    15.7 KB · Views: 141
Last edited:
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Sory I did not think this was important. Ive delete it and add it again and now:
B4X:
Biometric OK
va a autenticar...
biometricmanager_show (java line: 174)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at armi.portit.biometricmanager._show(biometricmanager.java:174)
    at armi.portit.mdashboard$ResumableSub_Activity_Create.resume(mdashboard.java:571)
    at armi.portit.mdashboard._activity_create(mdashboard.java:432)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at armi.portit.mdashboard.afterFirstLayout(mdashboard.java:105)
    at armi.portit.mdashboard.access$000(mdashboard.java:17)
    at armi.portit.mdashboard$WaitForLayout.run(mdashboard.java:83)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
biometricmanager_show (java line: 174)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at armi.portit.biometricmanager._show(biometricmanager.java:174)
    at armi.portit.mdashboard$ResumableSub_Activity_Create.resume(mdashboard.java:571)
Any help with this COnstructor not found error?
Thanks
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Any help with this COnstructor not found error?
I'm not so expert!

Ev.InitializeNewInstance(Application.PackageName & ".biometricmanager.BiometricPromptAuthentication", Array(Me))

Try setting the PackageName to b4a.example:
1618870202686.png


I write this because I have read:
Why have you renamed the class?
so maybe you also used an incorrect package name (although perhaps the compilation would not have been successful in this case).

Also try the project I attached to post #50 ? (update B4XPages first - download the new version and place it in the internal libraries folder)
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Thanks Lucas, Ive replace Me by Application.Packagename and same error() Im working with the original class without changes.
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
THis is the problem, Ive modified the example and put the code in a different module (testBiom) and got the same error. java.lang.RuntimeException: Constructor not found.
Atached the mod example app.
 

Attachments

  • BiomExample.zip
    11.4 KB · Views: 129
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Try this.
It works, but I am really not sure about it.
I think that using B4XPages would manage it much better.
It seems like the Biometric Check can be done only from Main Activity, that can manage the #AdditionalJar.
So what I am posting looks weird to me, but at least it show You a way to make it work.
But definitely I think it's a very dirty solution.
Or more probably I did something wrong. :rolleyes:

*** EDIT ***
Removed wrong example
 
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
As predicted I made something wrong.
The solution was to add
B4X:
#Extends: android.support.v7.app.AppCompatActivity
even to the second Activity.
 

Attachments

  • BiomExample.zip
    11.3 KB · Views: 139
Upvote 0
Top