smstuebe / xamarin-fingerprint

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

`NullReferenceException` on AuthenticationRequestConfiguration with beta #84

Closed kspearrin closed 4 years ago

kspearrin commented 6 years ago

1.4.6-beta3 seems to introduce a NullReferenceException on Android.

Steps to reproduce

var fingerprintRequest = new AuthenticationRequestConfiguration(AppResources.FingerprintDirection)
            {
                AllowAlternativeAuthentication = true,
                CancelTitle = AppResources.Cancel,
                FallbackTitle = AppResources.LogOut
            };
            var result = await _fingerprint.AuthenticateAsync(fingerprintRequest);

Expected behavior

No crash

Actual behavior

Crash

Crashlog

11-28 07:50:23.051 I/MonoDroid(26966): UNHANDLED EXCEPTION:
11-28 07:50:23.056 I/MonoDroid(26966): System.NullReferenceException: Object reference not set to an instance of an object.
11-28 07:50:23.056 I/MonoDroid(26966):   at Plugin.Fingerprint.Dialog.FingerprintDialogFragment.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x0000d] in C:\Projekte\xamarin-fingerprint\src\Plugin.Fingerprint.Android\Dialog\FingerprintDialogFragment.cs:156 
11-28 07:50:23.056 I/MonoDroid(26966):   at Android.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00020] in <e975227ac8644a30bb0866117325de0d>:0 
11-28 07:50:23.056 I/MonoDroid(26966):   at (wrapper dynamic-method) System.Object:b6ecdc56-c6bc-4f57-b633-f35b4213ced3 (intptr,intptr,intptr,intptr,intptr)

Configuration

Version of the Plugin: 1.4.6-beta3

Platform: Android 8.0

Device: Nexus 5X

smsissuechecker commented 6 years ago

Hi @kspearrin,

I'm the friendly issue checker. Thanks for using the issue template :star2: I appreciate it very much. I'm sure, the maintainers of this repository will answer, soon.

smstuebe commented 6 years ago

Hmm I can't reproduce it with my Nexus 5X ;( What was your previous version? Have you tried a clean build?

kspearrin commented 6 years ago

Going from 1.4.5 to 1.4.6-beta3. It was a clean build done by our CI system (appveyor). It also affected many more devices than just my Nexus 5x (was pushed out to our beta channel without proper testing, whoops!).

Targeting SDK 26. See https://github.com/bitwarden/mobile/commit/81700cfb44753aba02df5393d02d0f48668ce302

kspearrin commented 6 years ago

So I updated to 1.4.6-beta again with a clean install: https://github.com/bitwarden/mobile/commit/d255d44be5b64f20653dec2a16e5c90fecbd0629

After this, things started working again without issue.

Then after rebuilding the solution again, the resource designer file for Android changed (I guess to react to the changes from the lib update): https://github.com/bitwarden/mobile/commit/dc592831604a2b709358cb5386920e69a7f58029

After this the exception returned and the library does not work anymore with v1.4.6-beta3 (original issue from above).

Build log for broken version (v1.4.6-beta3): https://ci.appveyor.com/project/bitwarden/mobile/build/1127 Previous working version with 1.4.5: https://ci.appveyor.com/project/bitwarden/mobile/build/1125

smstuebe commented 6 years ago

In your commit you forgot to update UWP

UWP

https://github.com/bitwarden/mobile/blob/d255d44be5b64f20653dec2a16e5c90fecbd0629/src/UWP/UWP.csproj#L162-L164

Also see build log line 872

Android

https://github.com/bitwarden/mobile/blob/d255d44be5b64f20653dec2a16e5c90fecbd0629/src/Android/packages.config#L19

That's why your build log says (lines 4315 - 4321)

[00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Drawable.fingerprint_white. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj] [00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_btnCancel. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj] [00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_btnFallback. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj] [00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_imgFingerprint. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj] [00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_txtHelp. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj] [00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_txtReason. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj] [00:02:31] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Layout.FingerprintDialog. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]

I think this is the issue.

kspearrin commented 6 years ago

I updated UWP as well, unfortunately that didn't seem to change anything:

https://github.com/bitwarden/mobile/commit/ec9960e28e720590178ba14326ef7e68100cb2de

https://ci.appveyor.com/project/bitwarden/mobile/build/1128

Builds are still showing:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_btnCancel. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_btnFallback. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_imgFingerprint. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_txtHelp. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Id.fingerprint_txtReason. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1344,2): warning XA0106: Skipping Bit.Android.Resource.Layout.FingerprintDialog. Please check that your Nuget Package versions are compatible. [C:\projects\mobile\src\Android\Android.csproj]
kspearrin commented 6 years ago

Some Googling suggests it might have something to do with the Android Support package versions?

https://forums.xamarin.com/discussion/89661/a-lot-of-warnings-appear-in-a-new-empty-xamarin-forms-xaml-project https://github.com/UXDivers/Grial-UI-Kit-Support/issues/156 https://github.com/EgorBo/Toasts.Forms.Plugin/issues/117

smstuebe commented 6 years ago

Ye, I've seen these, too. But the only thing I did was updating my android SDK stuff. What's about you local build? Is it the same? Locally I've SDK 27 installed, but I can't select it as a target version. I hope Xamarin didn't mix it up under the hood.

kspearrin commented 6 years ago

Locally is the same issue. I am using SDK 26 locally and on AppVeyor.

smstuebe commented 6 years ago

Now, I can reproduce it locally. I uninstalled SDK 27. But even reinstalling SDK 27 didn't fix it #WTF 😖

smstuebe commented 6 years ago

Ok. Something is wrong with the build I guess. I'll go on tomorrow. gn8.

smstuebe commented 6 years ago

@kspearrin could you please try 1.4.6-beta4? 🤞

kspearrin commented 6 years ago

@smstuebe I'm still crashing on beta4:

https://github.com/bitwarden/mobile/commit/018fd83dbad2dfbe7faac069b269d21c3b128372

https://ci.appveyor.com/project/bitwarden/mobile/build/1141

Xamarin caused by: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
  at Plugin.Fingerprint.Dialog.FingerprintDialogFragment.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00023] in <598b4314a92545718b3db1aefda525ab>:0 
  at Android.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00020] in <85e9315a9597482895718a6b2f950b63>:0 
  at (wrapper dynamic-method) System.Object:fe8bece8-2772-4e3c-b9fe-e04f5eb5b1ad (intptr,intptr,intptr,intptr,intptr)
    at md500032558e65d65a9fc0bf95666812307.FingerprintDialogFragment.n_onCreateView(Native Method)
    at md500032558e65d65a9fc0bf95666812307.FingerprintDialogFragment.onCreateView(FingerprintDialogFragment.java:76)
    at android.app.Fragment.performCreateView(Fragment.java:2611)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1276)
    at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2415)
    at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2194)
    at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2148)
    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2049)
    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:718)
    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:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
smstuebe commented 6 years ago

WTF 😭

kspearrin commented 6 years ago

@smstuebe Are you still building with SDK 27? Maybe try a lower one?

smstuebe commented 6 years ago

I was building against 26 all the time. But I had 27 installed, thats why I thought Xamarin might get confused. Currently I'm implementing a sanity check for the build that builds a small project with the currently built nuget packages. But unfortunately I run into some msbuild bugs, that make that check harder ....

see: https://developercommunity.visualstudio.com/comments/159891/view.html

kspearrin commented 6 years ago

Actually, it seems to work with beta4 now. I forgot to update all project references when I tried earlier, which was causing it to reference beta3 bits in some areas. I uninstalled and reinstalled beta4 and now everything seems to be working correctly on my Nexus 5X. I will put this out to our play store beta channel and let you know if I receive any reports back about any problems.

smstuebe commented 6 years ago

Hmm but I could reproduce it with the beta4 build as well :(

KyleKofoed commented 6 years ago

@smstuebe @kspearrin
I might be able to shed some light here. I was able to get it to work after disabling the Plugin.Fingerprint.Test.UI.Android and rebuilding. I noticed in the Plugin.Fingerprint.Test.UI.Android\Resources\Resource.Designer.cs file that had the following: global::Plugin.Fingerprint.Resource.Layout.FingerprintDialog = global::Plugin.Fingerprint.Test.UI.Android.Resource.Layout.FingerprintDialog; ... // aapt resource value: 0x7f030000 public const int FingerprintDialog = 2130903040;

I had a similar issue when trying to introduce an xUnit testing application to my solution. It seems things go a little haywire when you build multiple android or iOS apps.

I am unsure of a way around this other than disabling the ui test project. Have you experienced this before?

KyleKofoed commented 6 years ago

@smstuebe @nielscup

Did the above comment help you out at all?

I suppose to add on: I noticed that the same exact value for the int for the FingerprintDialog resource was located in the sample and testing projects. I think that made the application reference the wrong resource causing it not to find the Views within OnCreateView.

KyleKofoed commented 6 years ago

Response from Microsoft:

"Yes this is a common problem teams run into with cross-platform frameworks like ReactNative, Xamarin, Cordova, etc.

As an interim workaround, you could try and create a build configuration that does not build the project that does not jive with the dependency, but that creates added complexity.

There's no real good solution here, but you can remove the annoyance from your workflow with a workaround."

rockclane commented 6 years ago

@smstuebe @kspearrin
I have updated to the latest version 14.6 ,I am still facing the problem of Null exception same stack trace which is generated previously ,My app crashes when launching the app itself ,Its working fine on IOS and Oppo Andriod phone but not working on Samsung S7 ,the device is running on Marshmallow: Versions 6.0.1 ,I have tried uninstalling and reinstalling to latest Version 14.6 ,That did not work for me ,Is tere any other solution regarding this ?

smstuebe commented 6 years ago

This stupid build task :/ do you see XAM... Warnings in your build output ?

KyleKofoed commented 6 years ago

@rockclane @smstuebe @kspearrin Did the above work around help with the issue reported by @rockclane? Did something change in the build to help resolve the issue? Haven't really been keeping track of this as I wasn't sure if the work around I suggested was acknowledged.

rockclane commented 6 years ago

@smsissuechecker The Output Window in debug Mode Looks This ,I have tried your Solution @KyleKofoed It still crashes ,

04-03 14:25:25.755 E/mono ( 8305): System.NullReferenceException: Object reference not set to an instance of an object. 04-03 14:25:25.755 E/mono ( 8305): at Plugin.Fingerprint.Dialog.FingerprintDialogFragment+d21.MoveNext () [0x0002f] in C:\Projekte\xamarin-fingerprint\src\Plugin.Fingerprint.Android\Dialog\FingerprintDialogFragment.cs:105 04-03 14:25:25.755 E/mono ( 8305): --- End of stack trace from previous location where exception was thrown --- 04-03 14:25:25.755 E/mono ( 8305): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 04-03 14:25:25.755 E/mono ( 8305): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 04-03 14:25:25.755 E/mono ( 8305): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 04-03 14:25:25.755 E/mono ( 8305): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 04-03 14:25:25.755 E/mono ( 8305): at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in :0 04-03 14:25:25.755 E/mono ( 8305): at Plugin.Fingerprint.Contract.AndroidFingerprintImplementationBase+d0.MoveNext () [0x00042] in C:\Projekte\xamarin-fingerprint\src\Plugin.Fingerprint.Android\Contract\AndroidFingerprintImplementationBase.cs:17

clund1981 commented 6 years ago

All: I was getting this same error. I had the CrossFingerprint configuration in place in the OnCreate in MainActivity.cs but I noticed that the current activity was null. After reviewing a few other unrelated (but similar) posts I added this line before the CrossFingerprint.SetCurrentActivityResolver config and that solved it for me:

CrossCurrentActivity.Current.Activity = this;

So my OnCreate looks something like this:

protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    CrossCurrentActivity.Current.Activity = this;

    // Fingerprint auth
    CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

    base.OnCreate(bundle);

    Forms.Init(this, bundle);
    Xamarin.FormsMaps.Init(this, bundle);
    LoadApplication(new App());
}

Hope this helps. If there are issues with this approach please let me know.

IaroslavTernovy commented 6 years ago

@clund1981 Worked for me! THX!

clund1981 commented 6 years ago

@IaroslavTernovy Awesome! Glad it helped.