我在两个项目中实现了以下代码,一个工作,另一个不工作,下面是代码。我已经检查过其他帖子说要使用com.google.gms:google-services
我已经添加了Xamarin.GooglePlayServices.basement
仍然会给出错误,GooglePlayServices插件应该用于Xamarin吗?
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
Firebase.FirebaseApp.InitializeApp(this);
Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;
buttonView = FindViewById<Button>(Resource.Id.button1);
error = FindViewById<TextView>(Resource.Id.error);
buttonView.Click += StartQueryDetailsAsync;
}
public async void StartQueryDetailsAsync(object sender, EventArgs e)
{
Dictionary<string, Java.Lang.Object> user = new Dictionary<string, Java.Lang.Object>
{
{ "PurchaseToken", purchase.PurchaseToken },
{ "QueryNumber", 1}
};
firestore = FirebaseFirestore.Instance;
firestore.Collection("DineUser").Document(purchase.Id).Set(user).AddOnSuccessListener(this);
}
错误:
{Java.Lang.IllegalArgumentException: FirebaseOptions.getProjectId() cannot be null at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method) [0x00068] in <8acc8089c2ed40d08469fbaa6710a44c>:0 at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod) [0x0000e] in <957bbfdfda4341e2939c881206c1140a>:0 at Firebase.Firestore.FirebaseFirestore.get_Instance () [0x0002f] in <97744bd4f3f740c1884b76e44794b938>:0 at DineCam.Main.DrawRect+<Purchase>d__56.MoveNext () [0x00417] in D:\DineCam\DineCam\Main\DrawRect.cs:427 --- End of managed Java.Lang.IllegalArgumentException stack trace --- java.lang.IllegalArgumentException: FirebaseOptions.getProjectId() cannot be null at com.google.firebase.firestore.FirebaseFirestore.zze(Unknown Source) at com.google.firebase.firestore.FirebaseFirestore.getInstance(Unknown Source) at md580a1eddd40074c89f21a5ec99d8b044c.DrawRect.n_onActivityResult(Native Method) at md580a1eddd40074c89f21a5ec99d8b044c.DrawRect.onActivityResult(DrawRect.java:86) at android.app.Activity.dispatchActivityResult(Activity.java:6508) at android.app.ActivityThread.deliverResults(ActivityThread.java:3925) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3972) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1537) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) }
我已将Xamarin.GooglePlayServices.basement和Xamarin.Firebase.Firestore版本从v60.1142.1稳定版本更改为v71.1500.0-preview1,将所有Xamarin.Android.Support库更改为v28.0.0.1,现在可以使用,以前是我的项目我不允许安装预览版,我创建了一个新项目并添加了预览版本,现在可以使用了。