smstuebe / xamarin-fingerprint

Xamarin and MvvMCross plugin for authenticate a user via fingerprint sensor
Microsoft Public License
494 stars 118 forks source link

GetAvailabilityAsync() is not returning any enum value running upon device with nosensor. #33

Closed ranjitrock closed 7 years ago

ranjitrock commented 7 years ago

I am running the sample code (GetAvailabilityAsync) to check behavior on device with no fingerprint sensor. It is throwing me exception rather than returning me enum value as NoSensor .

Exception: [SamsungFingerprintImplementation] com.samsung.android.sdk.SsdkUnsupportedException: This device does not provide FingerprintService. [SamsungFingerprintImplementation] at com.samsung.android.sdk.pass.Spass.initialize(Unknown Source)

Code: public async Task FingerPrintAuthentication() { var availability = await CrossFingerprint.Current.GetAvailabilityAsync(); }

Task.Run(async () => { await FingerPrintAuthentication(); });

Manifest: `

`

Device details: Device name: Samsung Galaxy S4(GT-19500) OS : 5.0.1 Sensor : No

smstuebe commented 7 years ago

Is it really throwing this exception (= app crashes) or just logging it or is just the debugger notifying you that this exception has been thrown? Spass.initialize is surrounded by a try-catch. It would be weird.

ranjitrock commented 7 years ago

The app is not crashing but it is not returning the enum value to proceed further. I ran the above code in Debug mode. Also When i run on Release mode i encountered "LinkAssemblies task failed unexpectedly" I am using xamarin studio. LinkAssemblies Error message:

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly. Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'Android.Hardware.Fingerprints.FingerprintManager/AuthenticationCallback' (defined in 'Plugin.Fingerprint, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null') from 'Plugin.Fingerprint, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve Android.Hardware.Fingerprints.FingerprintManager/AuthenticationCallback at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference) at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference) at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference) at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference) at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type) at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly) at Mono.Linker.Steps.MarkStep.Initialize() at Mono.Linker.Steps.MarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute() --- End of inner exception stack trace --- at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() (MSB4018) (fingerprint)

ranjitrock commented 7 years ago

I have solved the linker error - I had to modify the build settings but still i am not getting any enum from GetAvailabilityAsync() from my android application.

smstuebe commented 7 years ago

Do you build against a Android SDK >= 23?

ranjitrock commented 7 years ago

target version= 19

smstuebe commented 7 years ago

I mean compile Sdk Version.

ranjitrock commented 7 years ago

I am using Xamarin studio IDE . i checked the entire project settings there are no options to change compile sdk version. I even checked csproj file.

smstuebe commented 7 years ago

In the project file it should be here (example): https://github.com/smstuebe/xamarin-fingerprint/blob/master/src/Plugin.Fingerprint.Android/Plugin.Fingerprint.Android.csproj#L18

I'll look up where to set it in Xamarin Studio, when I'm at home.

smstuebe commented 7 years ago

This is the Target Framework. Should be >= 6.0

image

This must be set to automatic or something >= API 23 image

ranjitrock commented 7 years ago

Finally it it is working.I changed the target version 23 .I am able to get the enum value. Here are the logs from logcat. 12-01 09:40:43.881: W/SamsungFingerprintImplementation(16876): com.samsung.android.sdk.SsdkUnsupportedException: This device does not provide FingerprintService. 12-01 09:40:43.881: W/SamsungFingerprintImplementation(16876): at com.samsung.android.sdk.pass.Spass.initialize(Unknown Source) 12-01 09:40:43.901: D/fingerprint(16876): Availability enum NoApi

Thanks! Really appreciate it!

smstuebe commented 7 years ago

Ok. I'll document this and look up if it's possible to check the compile version at runtime to throw a meaningful exception.

smstuebe commented 7 years ago

Documentation added. Can't throw an exception, because the type load exception will be thrown when the lib gets loaded.