f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

Android - Does not work with Release build #106

Closed kd1002 closed 1 year ago

kd1002 commented 1 year ago

I am using Visual Studio 2022 Community 17.3.6 Plugin.CloudFirestore 4.1.0 Xamarin.Essentials 1.7.3 Xamarin.Forms 5.0.0.2515

When testing in Debug mode, everything works fine. Plugin.Authentication works fine as well. But when building with "Release" Plugin.CloudFirestore seems to break. When calling UpdateAsync, it just hangs, no response is given. When calling a query then GetAsync, that completes fine but after trying to get the keys or values like "document.Data.Keys", I get System.NullReferenceException

I have tried changing many settings in my Android project but nothing has seemed to work. Also tried using older versions of Plugin.CloudFirestore

Any help would be appreciated.

 try
            {
                var loginStatus = await CrossFirebaseAuth.Current.Instance.SignInWithEmailAndPasswordAsync(userNameBox.Text, passwordBox.Text);
                await DisplayAlert("Login Success", loginStatus.User.Uid, "OK");

                var queryDocument = CrossCloudFirestore.Current.Instance.Collection("Accounts").WhereEqualsTo("ID", loginStatus.User.Uid);
                var documentResult = await queryDocument.GetAsync();
                await DisplayAlert("Get Documents Success", documentResult.ToString(), "OK");
                var document = documentResult.Documents.FirstOrDefault();

                await DisplayAlert("Get first doucment success", documentResult.ToString(), "OK");

                List<string> userInfoKeys = new List<string>();
                List<string> userInfoValues = new List<string>();

                foreach (string key in document.Data.Keys) { userInfoKeys.Add(key); } // exception here
                await DisplayAlert("Get keys success", "OK", "OK");
                foreach (string value in document.Data.Values) { userInfoValues.Add(value); }
                await DisplayAlert("Get valuse success", "OK", "OK");

                await DisplayAlert("Get Info Success", CurrentUserMFEID, "OK");
            }
            catch(Exception ex)
            {
                await DisplayAlert("OK", ex.ToString(), "OK");
            }

          var loginStatus = await CrossFirebaseAuth.Current.Instance.SignInWithEmailAndPasswordAsync(
                        "username", "password");

                    await DisplayAlert("Login Success", loginStatus.User.Uid, "OK");

                    await CrossCloudFirestore.Current // hangs here
                         .Instance
                         .Collection("PasswordReset")
                         .Document(enteredEmail)
                         .UpdateAsync(new
                         {
                             Reset = "Yes"
                         });

                    await DisplayAlert("Success", "Request was successfull", "OK");

                    await Navigation.PushModalAsync(new NavigationPage(new MainPage()));
mrobraven commented 1 year ago

I would check that you have set all of the correct permissions in your manifest and that your rules are set correctly on firebase. I am not having any issues in release mode

kd1002 commented 1 year ago

Thanks for the response. It looks like Code shrinker in the Android Project settings was the problem. I had it set to "r8", changed it to nothing and that solved the problem.