Unable to write to Firebase Database from my Android application - android

This is the code I use to connect and write to the database (I want to create a new child node userand assign the value alex to it.
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("user").setValue("alex");
Note: I have followed the correct set-up instructions and have changed the authorisation of read and write to true. The code was working for about a month but now I can't figure out why its not writing to the database.
Below is my logcat
03-12 14:43:38.882 12158-12158/? I/art: Late-enabling -Xcheck:jni
03-12 14:43:38.900 12158-12165/? I/art: Debugger is no longer active
03-12 14:43:38.900 12158-12165/? I/art: Starting a blocking GC Instrumentation
03-12 14:43:38.923 12158-12158/? W/System: ClassLoader referenced unknown path: /data/app/anaysingh.anaytyproject-1/lib/arm
03-12 14:43:38.932 12158-12158/? I/InstantRun: Instant Run Runtime started. Android package is anaysingh.anaytyproject, real application class is null.
03-12 14:43:39.090 12158-12158/? W/System: ClassLoader referenced unknown path: /data/app/anaysingh.anaytyproject-1/lib/arm
03-12 14:43:39.127 12158-12158/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
03-12 14:43:39.136 12158-12158/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
03-12 14:43:39.247 12158-12158/? V/FA: Cancelling job. JobID: -129726599
03-12 14:43:39.253 12158-12158/? V/FA: Registered activity lifecycle callback
03-12 14:43:39.255 12158-12158/? I/FirebaseInitProvider: FirebaseApp initialization successful
03-12 14:43:39.264 12158-12174/? V/FA: Collection enabled
03-12 14:43:39.264 12158-12174/? V/FA: App package, google app id: anaysingh.anaytyproject, 1:1025179625916:android:afeaaa816280de9a
03-12 14:43:39.266 12158-12174/? I/FA: App measurement is starting up, version: 11910
03-12 14:43:39.266 12158-12174/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-12 14:43:39.266 12158-12174/? I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app anaysingh.anaytyproject
03-12 14:43:39.266 12158-12174/? D/FA: Debug-level message logging enabled
03-12 14:43:39.278 12158-12174/? V/FA: Connecting to remote service
03-12 14:43:39.293 12158-12174/? V/FA: Connection attempt already in progress
03-12 14:43:39.379 12158-12158/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-12 14:43:39.384 12158-12158/? V/FA: onActivityCreated
03-12 14:43:39.534 12158-12158/? D/Connection: https://anaytyproject.firebaseio.com/Nigga
03-12 14:43:39.551 12158-12174/? V/FA: Connection attempt already in progress
03-12 14:43:39.556 12158-12174/? I/FA: Tag Manager is not found and thus will not be used
03-12 14:43:39.557 12158-12174/? D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-4541290412013862895}]
03-12 14:43:39.559 12158-12177/? I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
03-12 14:43:39.559 12158-12177/? I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
03-12 14:43:39.566 12158-12177/? W/System: ClassLoader referenced unknown path:
03-12 14:43:39.573 12158-12174/? V/FA: Connection attempt already in progress
03-12 14:43:39.574 12158-12174/? V/FA: Activity resumed, time: 4225355
03-12 14:43:39.582 12158-12177/? W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000004c/n/armeabi-v7a
03-12 14:43:39.582 12158-12177/? W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000004c/n/armeabi
03-12 14:43:39.604 12158-12178/? I/Adreno: QUALCOMM build : bc479b6, I15255e4b4a
Build Date : 02/22/17
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.5.5.R1.07.00.00.269.019
Remote Branch : NONE
Reconstruct Branch : NOTHING
03-12 14:43:39.608 12158-12178/? I/OpenGLRenderer: Initialized EGL, version 1.4
03-12 14:43:39.608 12158-12178/? D/OpenGLRenderer: Swap behavior 1
03-12 14:43:39.625 12158-12179/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
03-12 14:43:39.659 12158-12174/? D/FA: Connected to remote service
03-12 14:43:39.660 12158-12174/? V/FA: Processing queued up service tasks: 4
03-12 14:43:44.701 12158-12174/anaysingh.anaytyproject V/FA: Inactivity, disconnecting from the service
03-12 14:43:56.840 12158-12174/anaysingh.anaytyproject V/FA: Recording user engagement, ms: 17290
03-12 14:43:56.840 12158-12174/anaysingh.anaytyproject V/FA: Connecting to remote service
03-12 14:43:56.842 12158-12174/anaysingh.anaytyproject V/FA: Activity paused, time: 4242644
03-12 14:43:56.844 12158-12174/anaysingh.anaytyproject D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=17290, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-4541290412013862895}]
03-12 14:43:56.852 12158-12174/anaysingh.anaytyproject V/FA: Connection attempt already in progress
03-12 14:43:56.852 12158-12174/anaysingh.anaytyproject D/FA: Connected to remote service
03-12 14:43:56.852 12158-12174/anaysingh.anaytyproject V/FA: Processing queued up service tasks: 2
What am I doing wrong, my firebase database still shows null. However when I add data manually and read via JS it is working correctly.

The errors tell you that you haven't linked Firebase to your project.
03-12 14:43:39.127 12158-12158/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
03-12 14:43:39.136 12158-12158/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
Use the Firebase Assistant to set it up:
To open the Firebase Assistant in Android Studio:
Click Tools > Firebase to open the Assistant window.
Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.
Full documentation here.

Related

Reading from Firebase Database without crashing

I'm creating an app that requires me to read from a fire base database and this value to alter layouts. I've tried using the 'help' from android studio but when I run the program it crashes. The photo I've attached is the 'help' not as code because it crashed the program and I wanted it work basically. So can anyone advise an easier method of reading from the database?
Thanks
12-04 11:38:44.004 3524-3524/com.example.jopayne1968.points4spending I/FA: App measurement is starting up, version: 11020
12-04 11:38:44.004 3524-3524/com.example.jopayne1968.points4spending I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
12-04 11:38:44.034 3524-3524/com.example.jopayne1968.points4spending V/FA: Collection enabled
12-04 11:38:44.034 3524-3524/com.example.jopayne1968.points4spending V/FA: App package, google app id: com.example.jopayne1968.points4spending, 1:723788589244:android:e3ad2acca46870b3
12-04 11:38:44.034 3524-3524/com.example.jopayne1968.points4spending I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.jopayne1968.points4spending
12-04 11:38:44.034 3524-3524/com.example.jopayne1968.points4spending D/FA: Debug-level message logging enabled
12-04 11:38:44.104 3524-3524/com.example.jopayne1968.points4spending V/FA: Registered activity lifecycle callback
12-04 11:38:44.114 3524-3630/com.example.jopayne1968.points4spending V/FA: Using measurement service
12-04 11:38:44.114 3524-3630/com.example.jopayne1968.points4spending V/FA: Connecting to remote service
12-04 11:38:44.114 3524-3630/com.example.jopayne1968.points4spending V/FA: Connection attempt already in progress
12-04 11:38:44.264 3524-3524/com.example.jopayne1968.points4spending V/FA: onActivityCreated
12-04 11:38:44.514 3524-3630/com.example.jopayne1968.points4spending V/FA: Using measurement service
12-04 11:38:44.514 3524-3630/com.example.jopayne1968.points4spending V/FA: Connection attempt already in progress
12-04 11:38:44.514 3524-3630/com.example.jopayne1968.points4spending V/FA: Activity resumed, time: 60750091
12-04 11:38:44.514 3524-3630/com.example.jopayne1968.points4spending I/FA: Tag Manager is not found and thus will not be used
12-04 11:38:44.514 3524-3630/com.example.jopayne1968.points4spending D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=SignUpActivity, firebase_screen_id(_si)=531904640859358265}]
12-04 11:38:44.544 3524-3630/com.example.jopayne1968.points4spending V/FA: Using measurement service
12-04 11:38:44.544 3524-3630/com.example.jopayne1968.points4spending V/FA: Connection attempt already in progress
12-04 11:38:44.744 3524-3630/com.example.jopayne1968.points4spending D/FA: Connected to remote service
12-04 11:38:44.744 3524-3630/com.example.jopayne1968.points4spending V/FA: Processing queued up service tasks: 4
12-04 11:38:44.794 3422-2815/? V/FA-SVC: Logging event: origin=auto,name=screen_view(_vs),params=Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=SignUpActivity, firebase_screen_id(_si)=531904640859358265}]
12-04 11:38:44.804 3422-2815/? V/FA-SVC: Saving event, name, data size: screen_view(_vs), 59
12-04 11:38:44.804 3422-2815/? V/FA-SVC: Event recorded: Event{appId='com.example.jopayne1968.points4spending', name='screen_view(_vs)', params=Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=SignUpActivity, firebase_screen_id(_si)=531904640859358265}]}
12-04 11:38:44.814 3422-2815/? V/FA-SVC: Upload scheduled in approximately ms: 3418911
12-04 11:38:44.814 3422-2815/? V/FA-SVC: Scheduling upload with GcmTaskService
12-04 11:38:44.814 3422-2815/? V/FA-SVC: Scheduling task with Gcm. Time3418911
12-04 11:38:44.824 3422-2815/? V/FA-SVC: Background event processing time, ms: 28
12-04 11:38:49.854 3524-3630/com.example.jopayne1968.points4spending V/FA: Inactivity, disconnecting from the service

Unable to get advertising id

While running the demo (https://github.com/androidthings/doorbell) on my respberry PI, I run into error like the following:
01-01 00:11:00.830 5672-5672/com.company.androidthings.doorbell I/CameraManagerGlobal: Connecting to camera service
01-01 00:11:00.835 5672-5672/com.company.androidthings.doorbell D/DoorbellCamera: Using camera id 0
01-01 00:11:00.853 5672-5723/com.company.androidthings.doorbell D/DoorbellCamera: Opened camera.
01-01 00:11:00.995 5672-5715/com.company.androidthings.doorbell I/FA: This instance being marked as an uploader
01-01 00:11:01.122 5672-5715/com.company.androidthings.doorbell D/FA: Unable to get advertising id: com.google.android.gms.common.GooglePlayServicesNotAvailableException: com.google.android.gms.measurement.internal.zzt.zzlx(Unknown Source)
01-01 00:11:01.253 5672-5732/com.company.androidthings.doorbell D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 10s
The following is the method I tried:
I did some research and find the following relevant post:
adjust/unity_sdk#88
Following the instruction to install play service with android SDK manage tool (using android studio). Clear the project. Rebuild. Install the new apk into respberry PI but still have the same error log.
I also checked on the firebase console, no picture was updated. Even from the android monitor, it was confirmed that button was pushed camera works as expected.
Regarding internet connection, I installed another app on the raspberry PI. It successfully sent the info to the server. It confirms the connectivity works as expected.
Any suggestion?
The log message you are seeing is from FirebaseAnalytics (the "FA" in the log tag), and makes sense since analytics is not enabled in this sample (unless you added code to enable it). Notice this is also a debug message (the "D" in the log tag) and not an error/warning.
This should not be affecting the Doorbell sample, so if you are not able to get the images uploaded properly to Firebase there is likely something else wrong with the project configuration and perhaps there are other clues deeper in the log.
It turns out that configuration is not appropriate. It uses the new SDK path which doesn't install google play service. Once I switch to the default SDK path of system which installed google play service. The logs looks different event though that message "Unable to get advertising id:" is still there. It seems (from FA log) the app can talk to the server.
04-24 15:22:53.659 16642-16642/? I/art: Late-enabling -Xcheck:jni
04-24 15:22:53.661 16642-16642/? W/art: Unknown instruction set features for ARM CPU variant (generic) using conservative defaults
04-24 15:22:53.709 16642-16649/? I/art: Debugger is no longer active
04-24 15:22:53.709 16642-16649/? I/art: Starting a blocking GC Instrumentation
04-24 15:22:54.610 16642-16642/? W/System: ClassLoader referenced unknown path: /data/app/com.company.androidthings.doorbell-1/lib/arm
04-24 15:22:54.678 16642-16642/com.company.androidthings.doorbell D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
04-24 15:22:54.712 16642-16642/com.company.androidthings.doorbell W/InstanceID/Rpc: Found 10007
04-24 15:22:54.723 16642-16642/com.company.androidthings.doorbell D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell I/FA: App measurement is starting up, version: 9452
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell D/FA: Debug logging enabled
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell D/FA: AppMeasurement singleton hash: 202124672
04-24 15:22:54.906 16642-16642/com.company.androidthings.doorbell V/FA: Collection enabled
04-24 15:22:54.907 16642-16642/com.company.androidthings.doorbell V/FA: App package, google app id: com.company.androidthings.doorbell, 1:821276198771:android:044f9c86291658f3
04-24 15:22:54.980 16642-16642/com.company.androidthings.doorbell V/FA: Registered activity lifecycle callback
04-24 15:22:54.986 16642-16642/com.company.androidthings.doorbell I/FirebaseInitProvider: FirebaseApp initialization successful
04-24 15:22:54.989 16642-16642/com.company.androidthings.doorbell I/InstantRun: starting instant run server: is main process
04-24 15:22:55.000 16642-16666/com.company.androidthings.doorbell V/FA: State of service unknown
04-24 15:22:55.000 16642-16666/com.company.androidthings.doorbell V/FA: Checking service availability
04-24 15:22:55.015 16642-16666/com.company.androidthings.doorbell W/GooglePlayServicesUtil: Google Play Store is missing.
04-24 15:22:55.015 16642-16666/com.company.androidthings.doorbell W/FA: Service invalid
04-24 15:22:55.016 16642-16666/com.company.androidthings.doorbell V/FA: Setting useService: false
04-24 15:22:55.019 16642-16666/com.company.androidthings.doorbell V/FA: Using local app measurement service
04-24 15:22:55.449 16642-16642/com.company.androidthings.doorbell V/FA: onActivityCreated
04-24 15:22:55.449 16642-16642/com.company.androidthings.doorbell D/DoorbellActivity: Doorbell Activity created.
04-24 15:22:55.450 16642-16642/com.company.androidthings.doorbell D/DoorbellActivity: No permission
04-24 15:22:55.502 16642-16666/com.company.androidthings.doorbell V/FA: Activity resumed, time: 331914987
04-24 15:22:55.530 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is starting up
04-24 15:22:55.563 16642-16642/com.company.androidthings.doorbell V/FA: Bound to IMeasurementService interface
04-24 15:22:55.565 16642-16666/com.company.androidthings.doorbell V/FA: Connected to service
04-24 15:22:55.566 16642-16666/com.company.androidthings.doorbell V/FA: Processing queued up service tasks: 1
04-24 15:22:59.196 16642-16666/com.company.androidthings.doorbell W/art: Long monitor contention with owner pool-2-thread-1 (16678) at long com.android.org.conscrypt.NativeCrypto.RSA_generate_key_ex(int, byte[])(NativeCrypto.java:-2) waiters=0 in java.lang.String com.google.firebase.iid.zzg.get(java.lang.String, java.lang.String) for 3.621s
04-24 15:22:59.236 16642-16666/com.company.androidthings.doorbell I/FA: This instance being marked as an uploader
04-24 15:22:59.696 16642-16666/com.company.androidthings.doorbell D/FA: Unable to get advertising id: com.google.android.gms.common.GooglePlayServicesNotAvailableException: com.google.android.gms.measurement.internal.zzt.zzlx(Unknown Source)
04-24 15:22:59.711 16642-16666/com.company.androidthings.doorbell D/FA: Setting user property: _fot, 1493049600000
04-24 15:22:59.719 16642-16666/com.company.androidthings.doorbell D/FA: User property set: _fot, 1493049600000
04-24 15:22:59.723 16642-16666/com.company.androidthings.doorbell V/FA: Logging event: origin=auto,name=_f,params=Bundle[{_c=1}]
04-24 15:22:59.790 16642-16666/com.company.androidthings.doorbell V/FA: Saving event, name, data size: _f, 22
04-24 15:22:59.792 16642-16666/com.company.androidthings.doorbell V/FA: Event recorded: Event{appId='com.company.androidthings.doorbell', name='_f', params=Bundle[{_c=1, _o=auto}]}
04-24 15:22:59.802 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 14436
04-24 15:22:59.807 16642-16666/com.company.androidthings.doorbell V/FA: Background event processing time, ms: 84
04-24 15:22:59.808 16642-16666/com.company.androidthings.doorbell V/FA: Logging event: origin=auto,name=_e,params=Bundle[{_et=1}]
04-24 15:22:59.840 16642-16666/com.company.androidthings.doorbell V/FA: Saving event, name, data size: _e, 23
04-24 15:22:59.841 16642-16666/com.company.androidthings.doorbell V/FA: Event recorded: Event{appId='com.company.androidthings.doorbell', name='_e', params=Bundle[{_o=auto, _et=1}]}
04-24 15:22:59.847 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 14390
04-24 15:22:59.853 16642-16666/com.company.androidthings.doorbell V/FA: Background event processing time, ms: 45
04-24 15:23:04.241 16642-16666/com.company.androidthings.doorbell V/FA: Inactivity, disconnecting from AppMeasurementService
04-24 15:23:04.276 16642-16642/com.company.androidthings.doorbell V/FA: onUnbind called for intent. action: com.google.android.gms.measurement.START
04-24 15:23:04.277 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is shutting down
04-24 15:23:05.504 16642-16666/com.company.androidthings.doorbell V/FA: Session started, time: 331924989
04-24 15:23:05.550 16642-16666/com.company.androidthings.doorbell I/FA: Tag Manager is not found and thus will not be used
04-24 15:23:05.552 16642-16666/com.company.androidthings.doorbell D/FA: Logging event (FE): _s, Bundle[{_o=auto}]
04-24 15:23:05.555 16642-16666/com.company.androidthings.doorbell V/FA: Using local app measurement service
04-24 15:23:05.562 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is starting up
04-24 15:23:05.564 16642-16642/com.company.androidthings.doorbell V/FA: Bound to IMeasurementService interface
04-24 15:23:05.564 16642-16666/com.company.androidthings.doorbell V/FA: Connected to service
04-24 15:23:05.565 16642-16666/com.company.androidthings.doorbell V/FA: Processing queued up service tasks: 1
04-24 15:23:05.572 16642-16666/com.company.androidthings.doorbell V/FA: Logging event: origin=auto,name=_s,params=Bundle[{_o=auto}]
04-24 15:23:05.594 16642-16666/com.company.androidthings.doorbell V/FA: Saving event, name, data size: _s, 14
04-24 15:23:05.596 16642-16666/com.company.androidthings.doorbell V/FA: Event recorded: Event{appId='com.company.androidthings.doorbell', name='_s', params=Bundle[{_o=auto}]}
04-24 15:23:05.655 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 14850
04-24 15:23:05.660 16642-16666/com.company.androidthings.doorbell V/FA: Background event processing time, ms: 89
04-24 15:23:10.577 16642-16666/com.company.androidthings.doorbell V/FA: Inactivity, disconnecting from AppMeasurementService
04-24 15:23:10.616 16642-16642/com.company.androidthings.doorbell V/FA: onUnbind called for intent. action: com.google.android.gms.measurement.START
04-24 15:23:10.618 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is shutting down
04-24 15:23:20.547 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementReceiver got: com.google.android.gms.measurement.UPLOAD
04-24 15:23:20.562 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is starting up
04-24 15:23:20.564 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService called. startId, action: 1, com.google.android.gms.measurement.UPLOAD
04-24 15:23:20.588 16642-16666/com.company.androidthings.doorbell V/FA: Fetching remote configuration: com.company.androidthings.doorbell
04-24 15:23:20.598 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService processed last upload request
04-24 15:23:20.598 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is shutting down
04-24 15:23:20.601 16642-17004/com.company.androidthings.doorbell D/NetworkSecurityConfig: No Network Security Config specified, using platform default
04-24 15:23:21.835 16642-16666/com.company.androidthings.doorbell V/FA: Parsed config. version, gmp_app_id: 1492543680583000, 1:821276198771:android:044f9c86291658f3
04-24 15:23:21.841 16642-16666/com.company.androidthings.doorbell V/FA: Successfully fetched config. Got network response. code, size: 200, 52
04-24 15:23:21.892 16642-16666/com.company.androidthings.doorbell V/FA: event, affected audience count: _f, 0
04-24 15:23:21.896 16642-16666/com.company.androidthings.doorbell V/FA: event, affected audience count: _e, 0
04-24 15:23:21.899 16642-16666/com.company.androidthings.doorbell V/FA: event, affected audience count: _s, 0
04-24 15:23:21.901 16642-16666/com.company.androidthings.doorbell V/FA: property, affected audience count: _fot, 0
04-24 15:23:21.924 16642-16666/com.company.androidthings.doorbell V/FA: Saving bundle, size: 301
04-24 15:23:21.947 16642-16666/com.company.androidthings.doorbell V/FA: Uploading data. app, uncompressed size, data: com.company.androidthings.doorbell, 356,
batch {
bundle {
protocol_version: 1
platform: android
gmp_version: 9452
uploading_gmp_version: 9452
gmp_app_id: 1:821276198771:android:044f9c86291658f3
app_id: com.company.androidthings.doorbell
app_version: 1.0
app_version_major: 1
firebase_instance_id: eNnLI0cB484
dev_cert_hash: -8029454304837808102
app_store: manual_install
upload_timestamp_millis: 1493047401878
start_timestamp_millis: 1493047379237
end_timestamp_millis: 1493047385505
app_instance_id: 570e158a1616db1ea428bad0ac67c079
os_version: 7.0
device_model: iot_rpi3
user_default_language: en-us
time_zone_offset_minutes: 0
bundle_sequential_index: 1
service_upload: false
user_property {
set_timestamp_millis: 1493047379237
name: _fot
int_value: 1493049600000
}
event {
name: _f
timestamp_millis: 1493047379237
previous_timestamp_millis: 0
param {
name: _c
int_value: 1
}
param {
name: _o
string_value: auto
}
}
event {
name: _e
timestamp_millis: 1493047379237
previous_timestamp_millis: 0
param {
name: _o
string_value: auto
}
param {
name: _et
int_value: 1
}
}
event {
name: _s
timestamp_millis: 1493047385505
previous_timestamp_millis: 0
param {
name: _o
string_value: auto
}
}
}
}
04-24 15:23:21.950 16642-17004/com.company.androidthings.doorbell V/FA: Uploading data. size: 315
04-24 15:23:22.025 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 3599959
04-24 15:23:22.030 16642-16666/com.company.androidthings.doorbell V/FA: Successful upload. Got network response. code, size: 204, 0

How to add Firebase into android

I want added Firebase into my application. I write below codes, but when running application I can't see TOKEN in log!
My dependencies :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.google.firebase:firebase-messaging:10.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Manifest :
<application>
...
<!--Firebase service-->
<service android:name=".CloudMSG.MyFirebaseInctanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</application>
MyFirebaseInctanceIdService :
public class MyFirebaseInctanceIdService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseInctance";
#Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d("MyFirebaseInctance", "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
//sendRegistrationToServer(refreshedToken);
}
}
Logs:
03-30 13:36:42.943 9487-9487/? I/art: Late-enabling -Xcheck:jni
03-30 13:36:43.218 9487-9487/com.example.mohammad.a1_firebase D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
03-30 13:36:43.269 9487-9487/com.example.mohammad.a1_firebase W/InstanceID/Rpc: Found 10004
03-30 13:36:43.298 9487-9487/com.example.mohammad.a1_firebase D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
03-30 13:36:43.364 9487-9487/com.example.mohammad.a1_firebase I/FA: App measurement is starting up, version: 10084
03-30 13:36:43.364 9487-9487/com.example.mohammad.a1_firebase I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-30 13:36:43.364 9487-9487/com.example.mohammad.a1_firebase D/FA: Debug-level message logging enabled
03-30 13:36:43.364 9487-9487/com.example.mohammad.a1_firebase D/FA: AppMeasurement singleton hash: 720240273
03-30 13:36:43.404 9487-9487/com.example.mohammad.a1_firebase V/FA: Collection enabled
03-30 13:36:43.404 9487-9487/com.example.mohammad.a1_firebase V/FA: App package, google app id: com.example.mohammad.a1_firebase, 1:685652680518:android:0280a3bc1c6da8cb
03-30 13:36:43.405 9487-9487/com.example.mohammad.a1_firebase I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.mohammad.a1_firebase
03-30 13:36:43.463 9487-9487/com.example.mohammad.a1_firebase V/FA: Registered activity lifecycle callback
03-30 13:36:43.465 9487-9487/com.example.mohammad.a1_firebase I/FirebaseInitProvider: FirebaseApp initialization successful
03-30 13:36:43.467 9487-9487/com.example.mohammad.a1_firebase I/InstantRun: Starting Instant Run Server for com.example.mohammad.a1_firebase
03-30 13:36:43.471 9487-9587/com.example.mohammad.a1_firebase V/FA: Using measurement service
03-30 13:36:43.489 9487-9587/com.example.mohammad.a1_firebase V/FA: Connecting to remote service
03-30 13:36:43.528 9487-9587/com.example.mohammad.a1_firebase W/GooglePlayServicesUtil: Google Play services out of date. Requires 10084000 but found 6599430
03-30 13:36:43.612 9487-9487/com.example.mohammad.a1_firebase D/ContextHelper: convertTheme. context->name=com.example.mohammad.a1_firebase themeResourceId=2131230883
03-30 13:36:43.656 9487-9487/com.example.mohammad.a1_firebase W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-30 13:36:43.690 9487-9487/com.example.mohammad.a1_firebase V/FA: onActivityCreated
03-30 13:36:43.696 9487-9487/com.example.mohammad.a1_firebase I/PhoneWindow: [generateLayout] setColorNavigationBar => color=0x ff000001
03-30 13:36:43.718 9487-9487/com.example.mohammad.a1_firebase D/PhoneWindowEx: [PWEx][generateLayout] setNavigationBarColor2 : colors=0xfff5f5f5
03-30 13:36:43.718 9487-9487/com.example.mohammad.a1_firebase I/PhoneWindow: [setNavigationBarColor2] color=0x fff5f5f5
03-30 13:36:43.859 9487-9587/com.example.mohammad.a1_firebase V/FA: Using measurement service
03-30 13:36:43.859 9487-9587/com.example.mohammad.a1_firebase V/FA: Connection attempt already in progress
03-30 13:36:43.864 9487-9587/com.example.mohammad.a1_firebase V/FA: Activity resumed, time: 1436094125
03-30 13:36:43.879 9487-9612/com.example.mohammad.a1_firebase D/OpenGLRenderer: Render dirty regions requested: true
03-30 13:36:43.881 9487-9612/com.example.mohammad.a1_firebase I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.013_msm8974_LA.BF.1.1.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.25.03.00
Build Date: 01/21/15 Wed
Local Branch: mybranch7061829
Remote Branch: quic/LA.BF.1.1.1_rb1.7
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.013 + NOTHING
03-30 13:36:43.882 9487-9612/com.example.mohammad.a1_firebase I/OpenGLRenderer: Initialized EGL, version 1.4
03-30 13:36:43.910 9487-9612/com.example.mohammad.a1_firebase D/OpenGLRenderer: Enabling debug mode 0
03-30 13:36:43.916 9487-9487/com.example.mohammad.a1_firebase D/Atlas: Validating map...
03-30 13:36:43.927 9487-9487/com.example.mohammad.a1_firebase W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
03-30 13:36:43.936 9487-9592/com.example.mohammad.a1_firebase D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 30s
03-30 13:36:44.008 9487-9502/com.example.mohammad.a1_firebase W/art: Suspending all threads took: 5.068ms
03-30 13:36:44.047 9487-9487/com.example.mohammad.a1_firebase W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-30 13:36:44.183 9487-9487/com.example.mohammad.a1_firebase I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#755dbad time:128236912
03-30 13:37:14.017 9487-10051/com.example.mohammad.a1_firebase D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 60s
How can I fix this issue and show Firebase token in logs?
Firebase onTokenRefresh() will only be called if your token changes. Before that you should invoke
FirebaseInstanceId.getInstance().getToken()
in your initial activity (like MainActivity) maybe.
why you not tried integrated android studio with firebase directly using Tools menu-->firebase
add this line Gradle :-Module(app)
compile 'com.google.firebase:firebase-crash:10.2.0'
compile 'com.google.firebase:firebase-auth:10.2.0'
Try to uninstall the application and re-install , you will see the
Refreshed token in the logcat.
Also check in firebase console that Anonymous sign-in status is
Enabled or not in Authentication menu -> Sign in method

'Unfortunately, app has stopped' is shown twice on the device and 'Application terminated' in android studio with no error being shown

I am developing an app using Android Studio.
The problem is that app gets crashed twice within few minutes of running it and besides Application terminated. and normal logs no error is shown in the logcat.
Here's complete logcat:
02/12 22:31:34: Launching app
Cold swapped changes.
$ adb shell am start -n "com.abc.xxx/com.abc.xxx.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 13399 on device micromax-micromax_aq4502-2864004C04884I2
I/art: Late-enabling -Xcheck:jni
W/System: ClassLoader referenced unknown path: /data/app/com.abc.xxx-2/lib/arm
I/InstantRun: Instant Run Runtime started. Android package is com.abc.xxx, real application class is null.
W/System: ClassLoader referenced unknown path: /data/app/com.abc.xxx-2/lib/arm
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I/art: Background sticky concurrent mark sweep GC freed 11281(1218KB) AllocSpace objects, 22(696KB) LOS objects, 15% free, 5MB/6MB, paused 13.077ms total 70.659ms
I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
I/DynamiteModule: Selected local version of com.google.android.gms.flags
W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:4
I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 4
W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000012/n/armeabi-v7a
W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000012/n/armeabi
I/FirebaseCrashApiImpl: FirebaseCrashApiImpl created by ClassLoader p[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000012/DynamiteModulesC_GmsCore_prodmnc_hdpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000012/n/armeabi-v7a, /data/user/0/com.google.android.gms/app_chimera/m/00000012/n/armeabi, /vendor/lib, /system/lib]]]
I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
I/DynamiteModule: Selected local version of com.google.android.gms.flags
W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
I/FA: App measurement is starting up, version: 10084
I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
D/FA: Debug-level message logging enabled
D/FA: AppMeasurement singleton hash: 198168520
V/FA: Collection enabled
V/FA: App package, google app id: com.abc.xxx, 1:987905869088:android:e7f50263e7b8aa58
I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.getsportalapp.sportal
V/FA: Registered activity lifecycle callback
I/FirebaseCrash: FirebaseCrash reporting initialized com.google.android.gms.internal.zzbks#e551d72
I/FirebaseInitProvider: FirebaseApp initialization successful
V/FA: Using measurement service
V/FA: Connecting to remote service
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
W/com.facebook.appevents.AppEventsLogger: activateApp events are being logged automatically. There's no need to call activateApp explicitly, this is safe to remove.
I/GAC: Building GoogleApiClient
I/CrashlyticsCore: Initializing Crashlytics 2.3.15.167
V/FA: Connection attempt already in progress
V/FA: Activity resumed, time: 824779068
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false
D/signedIn: onAuthStateChanged:signed_in:ShXMXdc5kHUQZWG3lGudJtt2
I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:5
I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 5
I/OpenGLRenderer: Initialized EGL, version 1.4
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
E/RecyclerView: No adapter attached; skipping layout
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 2
E/RecyclerView: No adapter attached; skipping layout
D/getInvitation: getInvitation: no deep link found.
D/called: again
D/cLat: 2.8418744
D/cLng: 8.7791019
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
W/PersistentConnection: pc_0 - Using an unspecified index. Consider adding '".indexOn": "g"' at geofire to your security and Firebase Database rules for better performance
W/PersistentConnection: pc_0 - Using an unspecified index. Consider adding '".indexOn": "g"' at geofire to your security and Firebase Database rules for better performance
W/PersistentConnection: pc_0 - Using an unspecified index. Consider adding '".indexOn": "g"' at geofire to your security and Firebase Database rules for better performance
W/PersistentConnection: pc_0 - Using an unspecified index. Consider adding '".indexOn": "g"' at geofire to your security and Firebase Database rules for better performance
W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000010/n/armeabi
D/DynamitePackage: Instantiated singleton DynamitePackage.
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
I/DynamiteModule: Considering local module com.google.android.gms.piccard.dynamite:0 and remote module com.google.android.gms.piccard.dynamite:12
I/DynamiteModule: Selected remote version of com.google.android.gms.piccard.dynamite, version >= 12
W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000010/n/armeabi
W/VideoCapabilities: Unrecognized profile/level 32768/2 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 8 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 8 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 8 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 8 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 8 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 8 for video/mp4v-es
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
I/Ads: Starting ad request.
I/WebViewFactory: Loading com.google.android.webview version 53.0.2785.124 (code 278512400)
D/diffAnother: -6283000
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 5738-5744)
I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {611ead6}
I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
I/chromium: [INFO:library_loader_hooks.cc(151)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
W/cr_media: Requires BLUETOOTH permission
W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
I/cr_Ime: ImeThread is not enabled.
E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 13399
I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:8 and remote module com.google.android.gms.tagmanager:9
I/DynamiteModule: Selected remote version of com.google.android.gms.tagmanager, version >= 9
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/GoogleTagManager: No container asset found in /assets/containers. Checking top level /assets directory for container assets.
W/GoogleTagManager: Tag Manager's event handler WILL NOT be installed (no container loaded)
I/GoogleTagManager: Tag Manager initilization took 213ms
V/FA: Using measurement service
V/FA: Connecting to remote service
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
I/Ads: Scheduling ad refresh 45000 milliseconds from now.
W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
I/cr_Ime: ImeThread is not enabled.
I/Ads: Ad finished loading.
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 13399
I/chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
D/diffAnother: 1129000
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
I/Ads: Starting ad request.
D/diffAnother: -6300000
W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
I/cr_Ime: ImeThread is not enabled.
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 13399
I/Ads: Scheduling ad refresh 45000 milliseconds from now.
I/Ads: Ad finished loading.
V/FA: Using measurement service
V/FA: Connecting to remote service
D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=29568, _sc=MainActivity, _si=-6311178554893906199}]
V/FA: Using measurement service
V/FA: Connection attempt already in progress
V/FA: Activity paused, time: 824808635
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 2
W/com.facebook.appevents.AppEventsLogger: activateApp events are being logged automatically. There's no need to call activateApp explicitly, this is safe to remove.
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
D/call1: called
D/call2: called
D/call1: called
D/call2: called
D/error1: ERROR1
D/error1: ERROR1
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
V/RenderScript: 0xb8457a88 Launching thread(s), CPUs 4
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
V/FA: Inactivity, disconnecting from the service
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
I/Ads: Ad is not visible. Not refreshing ad.
I/Ads: Scheduling ad refresh 60000 milliseconds from now.
I/Ads: Ad is not visible. Not refreshing ad.
I/Ads: Scheduling ad refresh 60000 milliseconds from now.
Application terminated.
I tried integrating crashlytics but even it doesn't show any error when the app crashes in this manner.
The question is how will I be able to fix the error if I don't even know what the error is?
Please help me with this.
I think the issue is related to your ad view.
In last line it is showing that ad is not visible.

Firebase (Android): Transaction.success(mutableData) causes app to crash

I'm trying to write a function to increment unread message count in a chatapp(android) using transaction in Firebase.
My database structure looks like:
The member list can in fact contain more than 2 users for a group chat which I intend to expand later.
Currently, messages can be added into the messageList but after adding to the messageList I want to increase the unreadCount for all other user except the sender as well. I realised that I need to make use of Transaction to make it atomic so this is my incrementUnreadCount code.
private static void incrementUnreadCount(String chatRoomId) {
DatabaseReference mDatabaseMemberList = mDatabaseChatRooms.child(chatRoomId).child("memberList");
mDatabaseMemberList.runTransaction(new Transaction.Handler() {
#Override
public Transaction.Result doTransaction(MutableData mutableData) {
Map<String, Map<String, Object>> tempMemberList = (Map<String, Map<String, Object>>) mutableData.getValue();
if (tempMemberList == null) {
return Transaction.abort();
}
for (String key : tempMemberList.keySet()) {
// if it is not a sender node
if (!key.equals(TutUserManager.getCurrentUid())) {
Map<String, Object> tempMap = tempMemberList.get(key);
long tempCount = (long) tempMap.get("unreadCount");
tempCount += 1;
tempMap.put("unreadCount", tempCount);
tempMemberList.put(key, tempMap);
}
}
mutableData.setValue(tempMemberList);
return Transaction.success(mutableData);
}
#Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
The following code works only when I send the second message. So the value of unreadCount is 1 less than what it is expected to be.
I read the doc and realised that for the null case it is supposed to be:
return Transaction.success(mutableData);
and not:
return Transaction.abort();
as abort() will make server abort the transaction instead of trying to make the transaction again.
I try to change the code above to use return ransaction.success(mutableData); but it causes the app to crash upon calling the function.
Did I miss something ?
This is what I get from the console:
11/14 23:19:25: Launching app
No apk changes detected since last installation, skipping installation of C:\Users\Potcharaphol\AndroidStudioProjects\Tut\app\build\outputs\apk\app-debug.apk
$ adb shell am force-stop com.pchatanan.tut
$ adb shell am start -n "com.pchatanan.tut/com.pchatanan.tut.MainActivities.GetStartedActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.pchatanan.tut.test | com.pchatanan.tut
Connecting to com.pchatanan.tut
E/HAL: load: id=gralloc != hmi->id=gralloc
I/System.out: Sending WAIT chunk
I/art: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8600', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1339)
I/InstantRun: Instant Run Runtime started. Android package is com.pchatanan.tut, real application class is null.
[ 11-14 23:19:29.241 2931: 2931 E/ ]
process stopped due to unexpected signal 13
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
[ 11-14 23:19:29.819 2931: 2931 E/ ]
process stopped due to unexpected signal 13
I/FA: App measurement is starting up, version: 9877
I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
I/FA: To enable faster debug mode event logging run:
adb shell setprop firebase.analytics.debug-mode com.pchatanan.tut
I/HwCust: Constructor found for class android.app.HwCustAlarmManagerImpl
I/FirebaseInitProvider: FirebaseApp initialization successful
I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
[ 11-14 23:19:30.422 2931: 2931 E/ ]
process stopped due to unexpected signal 13
I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
I/HwSecImmHelper: mSecurityInputMethodService is null
W/ActionBarDrawerToggle: DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);
I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:4
I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 4
W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000018/n/arm64-v8a
[ 11-14 23:19:31.068 2931: 2931 E/ ]
process stopped due to unexpected signal 13
E/HAL: load: id=gralloc != hmi->id=gralloc
I/OpenGLRenderer: Initialized EGL, version 1.4
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
[ 11-14 23:19:33.493 2931: 2931 E/ ]
process stopped due to unexpected signal 13
W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
[ 11-14 23:19:35.396 2931: 2931 E/ ]
process stopped due to unexpected signal 13
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
W/art: Suspending all threads took: 14.466ms
I/FA: Tag Manager is not found and thus will not be used
I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/HwSecImmHelper: mSecurityInputMethodService is null
I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
E/RecyclerView: No adapter attached; skipping layout
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
E/RecyclerView: No adapter attached; skipping layout
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
I/HwSecImmHelper: mSecurityInputMethodService is null
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I/Process: Sending signal. PID: 20588 SIG: 9
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
This is what I get from logcat, there seems to be no errors.
[ 11-14 23:21:49.129 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:49.321 21571-21571/com.pchatanan.tut I/System.out: waiting for debugger to settle...
11-14 23:21:49.522 21571-21571/com.pchatanan.tut I/System.out: waiting for debugger to settle...
11-14 23:21:49.723 21571-21571/com.pchatanan.tut I/System.out: waiting for debugger to settle...
[ 11-14 23:21:49.781 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:49.924 21571-21571/com.pchatanan.tut I/System.out: waiting for debugger to settle...
11-14 23:21:50.125 21571-21571/com.pchatanan.tut I/System.out: debugger has settled (1319)
11-14 23:21:50.149 21571-21571/com.pchatanan.tut I/InstantRun: Instant Run Runtime started. Android package is com.pchatanan.tut, real application class is null.
[ 11-14 23:21:50.364 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:50.842 21571-21633/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-14 23:21:50.863 21571-21633/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-14 23:21:50.973 21571-21571/com.pchatanan.tut I/FA: App measurement is starting up, version: 9877
11-14 23:21:50.973 21571-21571/com.pchatanan.tut I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
11-14 23:21:50.980 21571-21571/com.pchatanan.tut I/FA: To enable faster debug mode event logging run:
adb shell setprop firebase.analytics.debug-mode com.pchatanan.tut
[ 11-14 23:21:50.999 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:51.035 21571-21571/com.pchatanan.tut I/HwCust: Constructor found for class android.app.HwCustAlarmManagerImpl
11-14 23:21:51.043 21571-21571/com.pchatanan.tut I/FirebaseInitProvider: FirebaseApp initialization successful
11-14 23:21:51.140 21571-21571/com.pchatanan.tut I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
11-14 23:21:51.216 21571-21571/com.pchatanan.tut W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-14 23:21:51.601 21571-21571/com.pchatanan.tut I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
[ 11-14 23:21:51.609 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:51.875 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:21:51.925 21571-21571/com.pchatanan.tut W/ActionBarDrawerToggle: DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);
11-14 23:21:52.015 21571-21571/com.pchatanan.tut I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:4
11-14 23:21:52.015 21571-21571/com.pchatanan.tut I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 4
11-14 23:21:52.030 21571-21571/com.pchatanan.tut W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000018/n/arm64-v8a
11-14 23:21:52.192 21571-21651/com.pchatanan.tut E/HAL: load: id=gralloc != hmi->id=gralloc
11-14 23:21:52.193 21571-21651/com.pchatanan.tut I/OpenGLRenderer: Initialized EGL, version 1.4
11-14 23:21:52.194 21571-21666/com.pchatanan.tut I/System: core_booster, getBoosterConfig = false
[ 11-14 23:21:52.196 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:54.257 21571-21711/com.pchatanan.tut I/System: core_booster, getBoosterConfig = false
[ 11-14 23:21:54.586 2931: 2931 E/ ]
process stopped due to unexpected signal 13
[ 11-14 23:21:55.208 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:56.193 21571-21571/com.pchatanan.tut W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
11-14 23:21:56.248 21571-21743/com.pchatanan.tut I/System: core_booster, getBoosterConfig = false
11-14 23:21:56.279 21571-21743/com.pchatanan.tut I/System: core_booster, getBoosterConfig = false
[ 11-14 23:21:56.442 2931: 2931 E/ ]
process stopped due to unexpected signal 13
[ 11-14 23:21:57.081 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:21:57.204 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:21:57.206 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:01.561 21571-21633/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
[ 11-14 23:22:01.587 2931: 2931 E/ ]
process stopped due to unexpected signal 13
[ 11-14 23:22:02.195 2931: 2931 E/ ]
process stopped due to unexpected signal 13
[ 11-14 23:22:02.874 2931: 2931 E/ ]
process stopped due to unexpected signal 13
[ 11-14 23:22:03.487 2931: 2931 E/ ]
process stopped due to unexpected signal 13
11-14 23:22:07.605 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:07.720 21571-21641/com.pchatanan.tut I/FA: Tag Manager is not found and thus will not be used
11-14 23:22:07.775 21571-21571/com.pchatanan.tut I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
11-14 23:22:07.985 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:07.985 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:09.062 21571-21942/com.pchatanan.tut I/System: core_booster, getBoosterConfig = false
11-14 23:22:09.141 21571-21942/com.pchatanan.tut I/System: core_booster, getBoosterConfig = false
11-14 23:22:09.354 21571-21571/com.pchatanan.tut I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
11-14 23:22:09.454 21571-21571/com.pchatanan.tut E/RecyclerView: No adapter attached; skipping layout
11-14 23:22:09.471 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:09.472 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:09.476 21571-21571/com.pchatanan.tut E/RecyclerView: No adapter attached; skipping layout
11-14 23:22:10.246 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:10.308 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:10.309 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:10.313 21571-21571/com.pchatanan.tut I/HwSecImmHelper: mSecurityInputMethodService is null
11-14 23:22:13.747 21571-21571/com.pchatanan.tut I/Process: Sending signal. PID: 21571 SIG: 9
11-14 23:22:13.995 22048-22063/com.pchatanan.tut E/HAL: load: id=gralloc != hmi->id=gralloc
11-14 23:22:14.012 22048-22048/com.pchatanan.tut I/InstantRun: Instant Run Runtime started. Android package is com.pchatanan.tut, real application class is null.
11-14 23:22:14.575 22048-22083/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-14 23:22:14.659 22086-22100/com.pchatanan.tut E/HAL: load: id=gralloc != hmi->id=gralloc
11-14 23:22:14.679 22086-22086/com.pchatanan.tut I/InstantRun: Instant Run Runtime started. Android package is com.pchatanan.tut, real application class is null.
11-14 23:22:15.323 22086-22133/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-14 23:22:15.341 22086-22133/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-14 23:22:15.462 22086-22086/com.pchatanan.tut I/FA: App measurement is starting up, version: 9877
11-14 23:22:15.462 22086-22086/com.pchatanan.tut I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
11-14 23:22:15.471 22086-22086/com.pchatanan.tut I/FA: To enable faster debug mode event logging run:
adb shell setprop firebase.analytics.debug-mode com.pchatanan.tut
11-14 23:22:15.524 22086-22086/com.pchatanan.tut I/HwCust: Constructor found for class android.app.HwCustAlarmManagerImpl
11-14 23:22:15.532 22086-22086/com.pchatanan.tut I/FirebaseInitProvider: FirebaseApp initialization successful
11-14 23:22:25.611 22086-22133/com.pchatanan.tut W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
In stead of iterate through each node in the Transaction thread, I use .addListenerForSingleValueEvent and iterate through each node. Then for the one that needs to be updated, I run the transaction code. This method works fine.
This is illustrated in the following code:
private static void incrementUnreadCount(String chatRoomId) {
final DatabaseReference mDatabaseMemberList = mDatabaseChatRooms.child(chatRoomId).child("memberList");
mDatabaseMemberList.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot child : dataSnapshot.getChildren()){
if(!child.getKey().equals(TutUserManager.getCurrentUid())){
mDatabaseMemberList.child(child.getKey()).runTransaction(new Transaction.Handler() {
#Override
public Transaction.Result doTransaction(MutableData mutableData) {
Map<String, Object> tempData = (Map<String, Object>) mutableData.getValue();
if(tempData == null){
return Transaction.success(mutableData);
}
long unreadCount = (long) tempData.get("unreadCount");
unreadCount += 1;
tempData.put("unreadCount", unreadCount);
mutableData.setValue(tempData);
return Transaction.success(mutableData);
}
#Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

Categories

Resources