xamarin / GooglePlayServicesComponents

Other
315 stars 148 forks source link

Cannot create instance of FitnessOptions.Builder because no default constructor exists #289

Open Mechameesh opened 4 years ago

Mechameesh commented 4 years ago

Using the following nuget packages

Xamarin.Forms Version 4.3.0.947036 Xamarin.GooglePlayServices.Auth 71.1600.0 Xamarin.GooglePlayServices.Fitness 71.1601.0

OS

Windows 10 Version 1903

Description

Cannot create a Android.Gms.Fitness.FitnessOptions.Builder instance because FitnessOptions.Builder' does not contain a constructor that takes 0 arguments

Steps to Reproduce

  1. Write the following code
    var fitnessApiOptions = new FitnessOptions.Builder()
                .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateActivitySummary, FitnessOptions.AccessWrite)
                .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateSpeedSummary, FitnessOptions.AccessWrite)
                .Build();
  2. Observe that the error in the description appears on compile
Mechameesh commented 4 years ago

It seems that creating the builder has to be done through the InvokeBuilder() method on the FitnessOptions class.

Changed the code to

            var fitnessApiOptions = FitnessOptions.InvokeBuilder()
                .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateActivitySummary, FitnessOptions.AccessWrite)
                .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateSpeedSummary, FitnessOptions.AccessWrite)
                .Build();

and the FitnessOptions are created.

I'll keep the issue open because documentation is poor, and I would expect the mapped classes to behave like their java counterparts.