尝试获取 Firestore 数据库实例时获取 NoClassDefFoundError
Getting NoClassDefFoundError while trying to get Firestore Database instance
我正在尝试获取 Cloud Firestore 数据库的引用,但出现以下错误
Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/Preconditions;
我已经阅读了所有文档并尽我所能进行了检查。
- 我在我的项目中添加了Xamarin.Google.Guava包
- 启用 Multidex,清理并重建解决方案
- 我没有使用 Proguard
- FirebaseApp 不为空
- 我已将 GoogleServicesJson 的构建操作更改为 None 并手动构建 FirebaseApp 选项但得到了相同的结果
以下是包裹清单
Xamarin.Android.Support.Design {28.0.0.1}
Xamarin.Firebase.Firestore {71.1705.0}
Xamarin.Google.Guava {27.1.0.2}
这是我的 GetDatabase 方法
public FirebaseFirestore GetDatabase()
{
FirebaseFirestore data_base;
var app = FirebaseApp.InitializeApp(Application.Context);
if (app == null)
{
var options = new FirebaseOptions.Builder()
.SetProjectId("deliveryapp-254615")
.SetApplicationId("deliveryapp-254615")
.SetApiKey("AIzaSyD9HOqiYHFLsT4RspeZyElbhhqq5tNBXPs")
.SetDatabaseUrl("https://deliveryapp-254615.firebaseio.com")
.SetStorageBucket("deliveryapp-254615.appspot.com")
.Build();
app = FirebaseApp.InitializeApp(Application.Context, options);
}
data_base = FirebaseFirestore.GetInstance(app);
return data_base
}
调试日志如下
10-03 19:08:39.154 D/FirebaseApp(28559): com.google.firebase.iid.FirebaseInstanceId is not linked. Skipping initialization.
10-03 19:08:39.155 D/FirebaseApp(28559): com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
10-03 19:08:39.156 D/FirebaseApp(28559): com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization.
10-03 19:08:39.180 I/zygote (28559): Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.firestore.FirebaseFirestore>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/Function;
10-03 19:08:39.180 I/zygote (28559): at void mono.android.view.View_OnClickListenerImplementor.n_onClick(android.view.View) (View_OnClickListenerImplementor.java:-2)
10-03 19:08:39.180 I/zygote (28559): at void mono.android.view.View_OnClickListenerImplementor.onClick(android.view.View) (View_OnClickListenerImplementor.java:30)
10-03 19:08:39.180 I/zygote (28559): at boolean android.view.View.performClick() (View.java:6297)
10-03 19:08:39.180 I/zygote (28559): at void android.view.View$PerformClick.run() (View.java:24797)
10-03 19:08:39.180 I/zygote (28559): at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:790)
10-03 19:08:39.180 I/zygote (28559): at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:99)
10-03 19:08:39.180 I/zygote (28559): at void android.os.Looper.loop() (Looper.java:164)
10-03 19:08:39.180 I/zygote (28559): at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6626)
10-03 19:08:39.180 I/zygote (28559): at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
10-03 19:08:39.180 I/zygote (28559): at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
10-03 19:08:39.180 I/zygote (28559): at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:811)
10-03 19:08:39.180 I/zygote (28559): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.base.Function" on path: DexPathList[[zip file "/data/app/com.Voidron.Delivery_DemoApp-d9Ckk53XN-uid0HuJbaR0A==/base.apk"],nativeLibraryDirectories=[/data/app/com.Voidron.Delivery_DemoApp-d9Ckk53XN-uid0HuJbaR0A==/lib/arm, /data/app/com.Voidron.Delivery_DemoApp-d9Ckk53XN-uid0HuJbaR0A==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
10-03 19:08:39.180 I/zygote (28559): at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)
10-03 19:08:39.180 I/zygote (28559): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
10-03 19:08:39.180 I/zygote (28559): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
我设法使用来自 https://github.com/xamarin/GooglePlayServicesComponents/issues/258
的输入解决了这个问题
我所做的只是将 Guava 的软件包降级到 27.1.0.0,这似乎解决了问题
我正在尝试获取 Cloud Firestore 数据库的引用,但出现以下错误
Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/Preconditions;
我已经阅读了所有文档并尽我所能进行了检查。
- 我在我的项目中添加了Xamarin.Google.Guava包
- 启用 Multidex,清理并重建解决方案
- 我没有使用 Proguard
- FirebaseApp 不为空
- 我已将 GoogleServicesJson 的构建操作更改为 None 并手动构建 FirebaseApp 选项但得到了相同的结果
以下是包裹清单
Xamarin.Android.Support.Design {28.0.0.1}
Xamarin.Firebase.Firestore {71.1705.0}
Xamarin.Google.Guava {27.1.0.2}
这是我的 GetDatabase 方法
public FirebaseFirestore GetDatabase()
{
FirebaseFirestore data_base;
var app = FirebaseApp.InitializeApp(Application.Context);
if (app == null)
{
var options = new FirebaseOptions.Builder()
.SetProjectId("deliveryapp-254615")
.SetApplicationId("deliveryapp-254615")
.SetApiKey("AIzaSyD9HOqiYHFLsT4RspeZyElbhhqq5tNBXPs")
.SetDatabaseUrl("https://deliveryapp-254615.firebaseio.com")
.SetStorageBucket("deliveryapp-254615.appspot.com")
.Build();
app = FirebaseApp.InitializeApp(Application.Context, options);
}
data_base = FirebaseFirestore.GetInstance(app);
return data_base
}
调试日志如下
10-03 19:08:39.154 D/FirebaseApp(28559): com.google.firebase.iid.FirebaseInstanceId is not linked. Skipping initialization.
10-03 19:08:39.155 D/FirebaseApp(28559): com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
10-03 19:08:39.156 D/FirebaseApp(28559): com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization.
10-03 19:08:39.180 I/zygote (28559): Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.firestore.FirebaseFirestore>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/Function;
10-03 19:08:39.180 I/zygote (28559): at void mono.android.view.View_OnClickListenerImplementor.n_onClick(android.view.View) (View_OnClickListenerImplementor.java:-2)
10-03 19:08:39.180 I/zygote (28559): at void mono.android.view.View_OnClickListenerImplementor.onClick(android.view.View) (View_OnClickListenerImplementor.java:30)
10-03 19:08:39.180 I/zygote (28559): at boolean android.view.View.performClick() (View.java:6297)
10-03 19:08:39.180 I/zygote (28559): at void android.view.View$PerformClick.run() (View.java:24797)
10-03 19:08:39.180 I/zygote (28559): at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:790)
10-03 19:08:39.180 I/zygote (28559): at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:99)
10-03 19:08:39.180 I/zygote (28559): at void android.os.Looper.loop() (Looper.java:164)
10-03 19:08:39.180 I/zygote (28559): at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6626)
10-03 19:08:39.180 I/zygote (28559): at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
10-03 19:08:39.180 I/zygote (28559): at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
10-03 19:08:39.180 I/zygote (28559): at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:811)
10-03 19:08:39.180 I/zygote (28559): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.base.Function" on path: DexPathList[[zip file "/data/app/com.Voidron.Delivery_DemoApp-d9Ckk53XN-uid0HuJbaR0A==/base.apk"],nativeLibraryDirectories=[/data/app/com.Voidron.Delivery_DemoApp-d9Ckk53XN-uid0HuJbaR0A==/lib/arm, /data/app/com.Voidron.Delivery_DemoApp-d9Ckk53XN-uid0HuJbaR0A==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
10-03 19:08:39.180 I/zygote (28559): at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)
10-03 19:08:39.180 I/zygote (28559): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
10-03 19:08:39.180 I/zygote (28559): at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
我设法使用来自 https://github.com/xamarin/GooglePlayServicesComponents/issues/258
的输入解决了这个问题我所做的只是将 Guava 的软件包降级到 27.1.0.0,这似乎解决了问题