Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics library causes a null reference exception to occur when calling SecureStorage.Default.GetAsync(string) #384

Open
MaxxDelusional opened this issue Dec 5, 2024 · 1 comment

Comments

@MaxxDelusional
Copy link

MaxxDelusional commented Dec 5, 2024

I am not sure what is happening under the hood, but after adding Plugin.Firebase.Analytics (3.1.0) to my Maui application, calls to SecureStorage.Default.GetAsync(key) now throw a null reference exception.

Csproj

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0-ios' OR '$(TargetFramework)' == 'net9.0-android'">
    <PackageReference Include="Plugin.Firebase.Analytics" Version="3.1.0" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
    <GoogleServicesJson Include="Platforms\Android\google-services.json" Link="google-services.json" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
    <BundleResource Include="Platforms\iOS\GoogleService-Info.plist" Link="GoogleService-Info.plist" />
</ItemGroup>
	

Initialization code

public static MauiAppBuilder UseFirebaseAnalytics(this MauiAppBuilder builder)
{

	builder.ConfigureLifecycleEvents(events =>
	{
#if IOS
		events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) =>
		{
			Plugin.Firebase.Core.Platforms.iOS.CrossFirebase.Initialize();
			return false;
		}));
#elif ANDROID
		events.AddAndroid(android => android.OnCreate((activity, bundle) => {

			Plugin.Firebase.Core.Platforms.Android.CrossFirebase.Initialize(activity);
		}));
#endif
	});
	return builder;

}

I tried adding the following as per docs, but it didn't make a difference.

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.15.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.5.1" />
    <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.5.1" />
    <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.9.3.1" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.8.0.7" />
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core" Version="2.8.7.1" />
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx" Version="2.8.7.1" />
</ItemGroup>

I am using .Net 9. I have only tried this on Android (so far).

@AdamEssenmacher
Copy link
Collaborator

This is very strange. Can you share a minimal repro project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants