Reputation: 83
i tried to use Firestore for my Android application project, but when i run this code, which is basically the documentation code of Firestore:
protected Integer sendAllToBack () {
try {
FirebaseFirestore db = FirebaseFirestore.getInstance();
Map<String, Object> data = new HashMap<>();
data.put("toto", "tata");
db.collection("users").add(data);
} catch (Exception e) {
e.printStackTrace();
return 1;
}
return 0;
}
I get this error:
Process: xxxxxxxxxxxxxx, PID: 14497
java.lang.ExceptionInInitializerError
at com.google.firestore.v1.MapValue.newBuilder(com.google.firebase:firebase-firestore@@21.4.3:232)
at com.google.firebase.firestore.UserDataReader.parseMap(com.google.firebase:firebase-firestore@@21.4.3:290)
at com.google.firebase.firestore.UserDataReader.parseData(com.google.firebase:firebase-firestore@@21.4.3:251)
at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(com.google.firebase:firebase-firestore@@21.4.3:232)
at com.google.firebase.firestore.UserDataReader.parseMergeData(com.google.firebase:firebase-firestore@@21.4.3:87)
at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@21.4.3:165)
at xxxxxxxxxxxxx.MainActivity.sendAllToBack(MainActivity.java:298)
at xxxxxxxxxxxxx.MainActivity.onDestroy(MainActivity.java:317)
at android.app.Activity.performDestroy(Activity.java:8078)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1353)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5057)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5101)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2123)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.RuntimeException: Unable to get message info for com.google.firestore.v1.MapValue
at com.google.protobuf.GeneratedMessageInfoFactory.messageInfoFor(GeneratedMessageInfoFactory.java:62)
at com.google.protobuf.ManifestSchemaFactory$CompositeMessageInfoFactory.messageInfoFor(ManifestSchemaFactory.java:143)
at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:55)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:93)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:107)
at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:171)
at com.google.firestore.v1.MapValue.<clinit>(com.google.firebase:firebase-firestore@@21.4.3:490)
at com.google.firestore.v1.MapValue.newBuilder(com.google.firebase:firebase-firestore@@21.4.3:232)
at com.google.firebase.firestore.UserDataReader.parseMap(com.google.firebase:firebase-firestore@@21.4.3:290)
at com.google.firebase.firestore.UserDataReader.parseData(com.google.firebase:firebase-firestore@@21.4.3:251)
at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(com.google.firebase:firebase-firestore@@21.4.3:232)
at com.google.firebase.firestore.UserDataReader.parseMergeData(com.google.firebase:firebase-firestore@@21.4.3:87)
at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@21.4.3:165)
at com.bouygues.bysafe.MainActivity.sendAllToBack(MainActivity.java:298)
at com.bouygues.bysafe.MainActivity.onDestroy(MainActivity.java:317)
at android.app.Activity.performDestroy(Activity.java:8078)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1353)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5057)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5101)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2123)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.UnsupportedOperationException
at com.google.firestore.v1.MapValue.dynamicMethod(com.google.firebase:firebase-firestore@@21.4.3:482)
at com.google.protobuf.GeneratedMessageLite.dynamicMethod(GeneratedMessageLite.java:252)
at com.google.protobuf.GeneratedMessageLite.buildMessageInfo(GeneratedMessageLite.java:280)
at com.google.protobuf.GeneratedMessageInfoFactory.messageInfoFor(GeneratedMessageInfoFactory.java:60)
at com.google.protobuf.ManifestSchemaFactory$CompositeMessageInfoFactory.messageInfoFor(ManifestSchemaFactory.java:143)
at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:55)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:93)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:107)
at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:171)
at com.google.firestore.v1.MapValue.<clinit>(com.google.firebase:firebase-firestore@@21.4.3:490)
at com.google.firestore.v1.MapValue.newBuilder(com.google.firebase:firebase-firestore@@21.4.3:232)
at com.google.firebase.firestore.UserDataReader.parseMap(com.google.firebase:firebase-firestore@@21.4.3:290)
at com.google.firebase.firestore.UserDataReader.parseData(com.google.firebase:firebase-firestore@@21.4.3:251)
at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(com.google.firebase:firebase-firestore@@21.4.3:232)
at com.google.firebase.firestore.UserDataReader.parseMergeData(com.google.firebase:firebase-firestore@@21.4.3:87)
at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@21.4.3:165)
at com.bouygues.bysafe.MainActivity.sendAllToBack(MainActivity.java:298)
at com.bouygues.bysafe.MainActivity.onDestroy(MainActivity.java:317)
at android.app.Activity.performDestroy(Activity.java:8078)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1353)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5057)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5101)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2123)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Has anyone any clue about what i may be doing wrong ?
I tried with
db.collection("users").document("1").set(data, SetOptions.merge());
which is the code i wanted to run at the beginning and i had the exact issue.
This code is in the MainActivity of my Android application, and i call it in the onDestroy method.
Upvotes: 1
Views: 425
Reputation: 461
This is caused by library version mismatch. Now one can actually go to the trouble of trying to fix this but the docs had a solution which actually works.https://firebase.google.com/docs/android/setup#add-sdks
dependencies {
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:26.3.0')
// When using the BoM, you don't specify versions in Firebase library
// dependencies
// Declare the dependency for the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics'
// Declare the dependencies for any other desired Firebase products
// For example, declare the dependencies for Firebase Authentication and
// Cloud Firestore
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
To learn more about BOM see Android Bill Of Materials
Upvotes: 1