xamarin / GooglePlayServicesComponents

Other
314 stars 146 forks source link

Updated Sample for Xamarin.Firebase.Config #447

Open donatellijl opened 3 years ago

donatellijl commented 3 years ago

Xamarin.Android Version (eg: 6.0):

11.2.2.1

Operating System & Version (eg: Mac OSX 10.11):

Mac OSX 11.2.3

Google Play Services Version

Describe your Issue

I am trying to upgrade Xamarin.Firebase.Config from 71.1610.4 to 120.0.3. After upgrading and removing all the deprecated calls and replacing with the new methods, Firebase Remote Config is no longer working. I have copied the code from the FirebaseConfigQuickstart sample project, but I get an error "Java.Lang.IllegalMonitorStateException: object not locked by thread before wait()" on any call that had .Wait() at the end.

If I remove the .Wait(), I get this error on calling FetchAsync(), "{Firebase.RemoteConfig.FirebaseRemoteConfigClientException: Firebase Installations failed to get installation auth token for fetch. ---> Firebase.Installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later…}"

I am not able to get the FirebaseConfigQuickstart project to work either. It builds, but crashes on open with the error "java.lang.RuntimeException: Unable to instantiate application androidx.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.xamarin.firebase.configquickstart-MRg5oGkzFAa2yGuZxRptfQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.xamarin.firebase.configquickstart-MRg5oGkzFAa2yGuZxRptfQ==/lib/x86, /data/app/com.xamarin.firebase.configquickstart-MRg5oGkzFAa2yGuZxRptfQ==/base.apk!/lib/x86, /system/lib, /system/product/lib]]". The sample project is also currently using 119.1.1.

Can you upgrade the sample project to use 120.0.3 and demonstrate a working example?

Relevant information

Add relevant project settings from *.csproj file:

Packages used:

    <PackageReference Include="Xamarin.AndroidX.AppCompat">
      <Version>1.2.0.7</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Browser">
      <Version>1.2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Core">
      <Version>1.3.2.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4">
      <Version>1.0.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
      <Version>2.2.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.6.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.Material">
      <Version>1.0.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Analytics">
      <Version>118.0.2</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Config">
      <Version>120.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Collections">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Iid">
      <Version>121.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Vision">
      <Version>71.1702.4</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.ZXing.Core">
      <Version>3.3.3</Version>
    </PackageReference>

Build settings (tools)

    <DebugSymbols>true</DebugSymbols>
    <DebugType>portable</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <MandroidI18n />
    <AndroidDexTool>d8</AndroidDexTool>
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <AndroidUseAapt2>true</AndroidUseAapt2>
    <AndroidLinkMode>None</AndroidLinkMode>

Info from Google about removing the methods we are currently using on 71.1610.4: Remote Config version 20.0.0

Minimal Repro Code Sample

public class RemoteConfigService : IRemoteConfigService
    {
        public RemoteConfigService()
        {
            FirebaseRemoteConfig.Instance.SetDefaultsAsync(Resource.Xml.remote_config_defaults).Wait();
#if DEBUG
            FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().Build();
            FirebaseRemoteConfig.Instance.SetConfigSettingsAsync(configSettings).Wait();
#endif
        }

        public async System.Threading.Tasks.Task FetchAndActivateAsync()
        {
            long cacheExpiration = 3600; // 1 hour in seconds.
            try
            {
                await FirebaseRemoteConfig.Instance.FetchAsync(cacheExpiration);
                FirebaseRemoteConfig.Instance.Activate().Wait();
            }
            catch (System.Exception e)
            {
                var error = "firebase connection error " + e.Message;
            }
        }

        public async Task<TInput> GetAsync<TInput>(string key)
        {
            var settings = FirebaseRemoteConfig.Instance.GetString(key);
            return await Task.FromResult(Newtonsoft.Json.JsonConvert.DeserializeObject<TInput>(settings));
        }
}

Steps to Reproduce (with link to sample solution if possible):

Upgrade Xamarin.Firebase.Config to 120.0.3.

a-pier commented 3 years ago

Any progress on this I also cannot get your sample project to build, receive error

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Java.Lang.IllegalMonitorStateException: object not locked by thread before wait() at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMet…

Please advise.