FirebaseFireStore Exception in Xamarin Android

velichety 1 Reputation point
2020-11-29T20:53:02.737+00:00

Hi there,

I'm trying to access Google Firebase Cloud Firestore collection through the following code. The app is not null. However, the getinstance throws an error -

"Failed resolution of: Lcom/google/common/io/BaseEncoding" error and crashes during runtime.

var baseOptions = Firebase.FirebaseOptions.FromResource(context);
            var options = new Firebase.FirebaseOptions.Builder(baseOptions).SetProjectId(baseOptions.
``StorageBucket.Split('.')[0]).Build();
            app = Firebase.FirebaseApp.InitializeApp(context, options, AppName);
            if (app != null)
            {

                var temp = FirebaseFirestore.GetInstance(app);
            }
  • I have the following project references
  • <PackageReference Include="Xamarin.Firebase.Core">
    <Version>117.4.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Build.Download">
    <Version>0.10.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Auth">
    <Version>119.3.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Guava" Exclude="all">
    <Version>27.1.0.4</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Firestore">
    <Version>121.4.3</Version>
    </PackageReference>

I also add Guava package by right clicking and adding it at package level.

Can you please suggest how I can resolve this error?

Developer technologies .NET Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. velichety 1 Reputation point
    2020-11-30T13:16:00.13+00:00

    Nugets seem to be on auto update. I dont see anything in updates.

    Posting some code -

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity  
    {  
    
    
        protected override void OnCreate(Bundle savedInstanceState)  
        {  
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);  
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);  
            Xamarin.Forms.DependencyService.Register<FirebaseAuthentication>();  
    
            //FirebaseApp.InitializeApp(Application.Context);  
             
            LoadApplication(new App());  
            FirestoreService.Init(this);  
       }  
    

    }

    FirestoreService.cs

    public class FirestoreService  
    {  
        private static Firebase.FirebaseApp app;  
        public static FirebaseFirestore Instance  
        {  
            get  
            {  
                return FirebaseFirestore.GetInstance(app);  
            }  
        }  
    
        public static string AppName { get; } = "SampleApp";  
    
        public static void Init(Android.Content.Context context)  
        {  
            var baseOptions = Firebase.FirebaseOptions.FromResource(context);  
            var options = new Firebase.FirebaseOptions.Builder(baseOptions).SetProjectId(baseOptions.StorageBucket.Split('.')[0]).Build();  
            app = Firebase.FirebaseApp.InitializeApp(context, options, AppName);  
            if (app != null)  
            {  
                  
                var temp = FirebaseFirestore.GetInstance(app);  
            }  
        }  
    }  
    

    FIrebase authentication works fine for me. But the Cloud Firestore crashes with the message as shown in attached.43659-screen-shot-2020-11-30-at-80759-am.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.