TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

FirebaseAuthException when enabling R8 on android #131

Closed tranb3r closed 12 months ago

tranb3r commented 1 year ago

I'm having this exception when trying to sign in with firebase, if android R8 is enabled:

Plugin.Firebase.Common.FirebaseAuthException: An internal error has occurred. [ Instantiation of JsonResponse failed! class com.google.android.gms.internal.firebase-auth-api.zzaah ]
at Plugin.Firebase.Auth.FirebaseAuthImplementation.SignInWithEmailAndPasswordAsync(String email, String password, Boolean createsUserAutomatically)

Here is how to enable android R8: add <AndroidLinkTool>r8</AndroidLinkTool> to csproj.

I've managed to fix the issue by adding to my app a proguard configuration file with this rule : -keep class com.google.android.gms.internal.firebase-auth-api.** { *; }

I think it would be useful to add this proguard rule to Plugin.Firebase nuget. What do you think ?

TobiasBuchholz commented 1 year ago

Ok, thanks for the info! Yeah, I guess it couldn't hurt to add this to the proguard configuration, so I'll do so for the next version.

vhugogarcia commented 12 months ago

@tranb3r could you please guide me on how to add that rule to a proguard file in .NET MAUI or a link with a guide? 🙏🏻 should I add a file to the root of the project or under /platforms/android/ folder? Which extension and build mode you set to the file?

I would like to enable R8 also on my Android app and I am getting the same error you faced.

I tried to look for .NET MAUI information but I only found for Xamarin.Forms.

Thanks in advance 🙂

tranb3r commented 12 months ago

@vhugogarcia

It's really easy to add a proguard configuration file to your app.

Another way to do that is to edit your csproj:

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
    <ProguardConfiguration Include="Platforms\Android\Proguard.cfg" />
</ItemGroup>
tranb3r commented 12 months ago

@TobiasBuchholz Maybe we could try to fix this issue in the next release. It's simply consists in including a targets file in the Auth nuget. I see you don't use a nuspec file. Do you know how to include a targets file when using msbuild/csproj?

tranb3r commented 12 months ago

@TobiasBuchholz The proguard rules have been updated in recent versions of Xamarin.Firebase.Auth. The issue will probably be resolved when updating the dependency from 121.0.8 to a more recevent version.

TobiasBuchholz commented 12 months ago

I've bumbed up Xamarin.Firebase.Auth to the newest version and released it with Plugin.Firebase.Auth 2.0.5 or Plugin.Firebase 2.0.9.

@tranb3r can you confirm this fixes the issue?

tranb3r commented 12 months ago

@TobiasBuchholz Yes, it works. Thanks! No need to add firebase-auth-api proguard rules to the app anymore.