braze-inc / braze-cordova-sdk

Public repo for the Braze Cordova SDK
https://www.braze.com
Other
21 stars 63 forks source link

Android not registering tokens #47

Closed sean-browze closed 4 years ago

sean-browze commented 4 years ago

Seem to be having an issue with getting tokens registered on Android. Here is my logcat output:

12-03 11:59:07.469  1820  1911 V Appboy v3.8.0 .com.appboy.Appboy: Starting up a new user dependency manager
12-03 11:59:07.469  1820  1910 I Appboy v3.8.0 .com.appboy.Appboy: Firebase Cloud Messaging found. Setting up Firebase Cloud Messaging.
12-03 11:59:07.469  1820  1910 V Appboy v3.8.0 .bo.app.bs: Registering for Firebase Cloud Messaging token using sender id: [MY_SENDER_ID]
12-03 11:59:07.470  1820  1904 I Appboy v3.8.0 .com.appboy.configuration.AppboyConfigurationProvider: Found an override api key. Using it to configure Appboy.
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs: Failed to register for Firebase Cloud Messaging using sender ID: [MY_SENDER_ID]
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process [APP_NAME]. Make sure to call FirebaseApp.initializeApp(Context) first.
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.1.0:245)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:1)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at bo.app.bs.b(SourceFile:107)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at bo.app.bs.a(SourceFile:42)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at com.appboy.Appboy$12.run(SourceFile:249)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12-03 11:59:07.476  1820  1910 E Appboy v3.8.0 .bo.app.bs:  at java.lang.Thread.run(Thread.java:764)
12-03 11:59:07.476  1820  1910 W Appboy v3.8.0 .bo.app.bs: Obtained an empty or null Firebase Cloud Messaging registration token. Not registering token.
12-03 11:59:07.477  1820  1910 D Appboy v3.8.0 .com.appboy.configuration.CachedConfigurationProvider: Unable to find the xml boolean configuration value with key com_appboy_push_adm_messaging_registration_enabled. Using default value 'false'.
12-03 11:59:07.477  1820  1910 D Appboy v3.8.0 .com.appboy.configuration.CachedConfigurationProvider: Defaulting to using xml value for key: com_appboy_push_adm_messaging_registration_enabled and value: false

I'm assuming it might have something to do with:

FirebaseApp is not initialized in this process [APP_NAME]. Make sure to call FirebaseApp.initializeApp(Context) first.

I've read through the documentation several times and I've gone through another app of ours that has no problem registering token and receiving push notifications. Not sure what the issue might be but would appreciate any guidance.

I should add, changeUser and event logging are working fine.

radixdev commented 4 years ago

Hi @sean-browze ,

I can't reproduce with our sample project. Can you provide a list of:

  1. Any possible customizations
  2. Other cordova plugins applied
  3. Version of the Braze Cordova SDK being used
  4. What device this is being seen on
  5. Complete steps to reproduce this issue
  6. Output of running cordova platform; cordova -v
sean-browze commented 4 years ago

@radixdev, thanks for the reply.

I cloned the sample repo and it's actually working fine so it seems it must be something on my end.

  1. I don't have any possible customizations.

  2. See below:

branch-cordova-sdk 3.2.0 "branch-cordova-sdk"
card.io.cordova.mobilesdk 2.1.0 "CardIO"
code-push 3.0.1 "CodePushAcquisition"
com.paypal.cordova.mobilesdk 3.5.0 "PayPalMobile"
cordova-plugin-advanced-http 2.2.0 "Advanced HTTP plugin"
cordova-plugin-appboy 2.12.0 "Device"
cordova-plugin-appsflyer-sdk 4.4.22 "AppsFlyer"
cordova-plugin-camera 4.1.0 "Camera"
cordova-plugin-code-push 1.12.0 "CodePush"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-facebook4 6.2.0 "Facebook Connect"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-googleplus 8.2.0 "Google SignIn"
cordova-plugin-inappbrowser 3.1.0 "InAppBrowser"
cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
cordova-plugin-keyboard 1.2.0 "Keyboard"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-x-socialsharing 5.6.0 "SocialSharing"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
es6-promise-plugin 4.2.2 "Promise"
  1. 2.12.0
  2. Galaxy S9
  3. Tried to reproduce with sample app and couldn't. Used same config.xml prefs and google-services.json but it worked with the sample app.
  4. See below:
Installed platforms:
  android 8.0.0
  ios 5.0.1
Available platforms: 
  browser ^6.0.0
  electron ^1.0.0
  osx ^5.0.0
  windows ^7.0.0
9.0.0 (cordova-lib@9.0.1)

More logcat info:

Working sample app:

12-04 14:08:53.882 19283 19374 I Appboy v3.8.0 .com.appboy.Appboy: Firebase Cloud Messaging found. Setting up Firebase Cloud Messaging.
12-04 14:08:53.882 19283 19374 V Appboy v3.8.0 .bo.app.bs: Registering for Firebase Cloud Messaging token using sender id:[SENDER_ID]
12-04 14:08:53.883 19283 19377 I Appboy v3.8.0 .com.appboy.configuration.AppboyConfigurationProvider: Found an override api key. Using it to configure Appboy.
12-04 14:08:53.888 19283 19374 V Appboy v3.8.0 .bo.app.bs: Obtained Firebase Cloud Messaging token: [TOKEN]
12-04 14:08:53.888 19283 19374 I Appboy v3.8.0 .com.appboy.Appboy: Push token [TOKEN] registered and immediately being flushed.

My app:

12-04 14:15:50.470 22237 22456 I Appboy v3.8.0 .com.appboy.Appboy: Firebase Cloud Messaging found. Setting up Firebase Cloud Messaging.
12-04 14:15:50.470 22237 22456 V Appboy v3.8.0 .bo.app.bs: Registering for Firebase Cloud Messaging token using sender id: [SENDER_ID]
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs: Failed to register for Firebase Cloud Messaging using sender ID: [SENDER_ID]
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process [APP_NAME]. Make sure to call FirebaseApp.initializeApp(Context) first.
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.1.0:245)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:1)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at bo.app.bs.b(SourceFile:107)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at bo.app.bs.a(SourceFile:42)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at com.appboy.Appboy$12.run(SourceFile:249)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12-04 14:15:50.486 22237 22456 E Appboy v3.8.0 .bo.app.bs:  at java.lang.Thread.run(Thread.java:764)
12-04 14:15:50.486 22237 22456 W Appboy v3.8.0 .bo.app.bs: Obtained an empty or null Firebase Cloud Messaging registration token. Not registering token.

Could another plugin be breaking this? Any ideas on what I could look into?

sean-browze commented 4 years ago

Another interesting thing to note is that when I run cordova run android on the working sample app, it parses google-services.json

Task :app:processDebugGoogleServices
Parsing json file: /Docs/appboy-cordova-sdk/sample-project/platforms/android/app/google-services.json

This doesn't happen when I run cordova run android on the broken app. It doesn't even look for google-services.json.

Bucimis commented 4 years ago

@sean-browze good find, you should ensure google-services.json is in a valid location per https://developers.google.com/android/guides/google-services-plugin

sean-browze commented 4 years ago

@Bucimis, thanks for the link. I figured this might have something to do with it. Any idea why the sample app will fail when building if I don't have the google-services.json file in the correct location but my current app doesn't even check if it exists? Not sure what else to do to try to my app to pick up the file. I figured it should automatically try when classpath 'com.google.gms:google-services:4.3.3' is dropped in.

Bucimis commented 4 years ago

@sean-browze you also need to add apply plugin: 'com.google.gms.google-services'. Could also be a gradle build plugin version difference

sean-browze commented 4 years ago

@Bucimis you led me on the right path, thanks! It's working now. Not sure why, but I need to take these additional steps to get it to work:

Any idea why this isn't working out of the box for me?

Bucimis commented 4 years ago

@sean-browze typically our build-extras.gradle file which contains relevant apply and classpath statements is included automatically via https://github.com/Appboy/appboy-cordova-sdk/blob/master/plugin.xml#L21 - so I would check if the extra gradle file is actually referenced by your project.

Regardless, as long as the google services plugin is available you should be in good shape. It doesn't matter whether it's included by you or by the Braze plugin