OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.57k stars 375 forks source link

OneSignal Android SDK not finding custom NotificationServiceExtension class #1327

Closed sweatherall closed 3 years ago

sweatherall commented 3 years ago

Description: I am upgrading an app from OneSignal v3 -> v4, and I am following these instructions to implement the functionality of receiving a push notification while the app is in background on Android. However, there is an issue during initialization where it is not finding/initializing my NotificationServiceExtension class, and I'm not sure why.

Environment RN: 0.66.3 react-native-onesignal: 4.3.3 installed via npm

Steps to Reproduce Issue:

  1. Install the OneSignal SDK using npm into your project
  2. Create the Android Notification Service Extension following these instructions
  3. Initialize OneSignal within react native app
  4. Start up the RN app, see error in logcats

Logcats on app start up:

2021-11-23 14:25:42.028 W/OneSignal: appId set, but please call initWithContext(appContext) with Application context to complete OneSignal init!
2021-11-23 14:25:48.948 D/OneSignal: Adding a task to the pending queue with ID: 1
2021-11-23 14:25:48.948 D/OneSignal: startPendingTasks with task queue quantity: 1
2021-11-23 14:25:48.952 D/OneSignal: Attempted to clean 6 month old IAM data, but none exists!
2021-11-23 14:25:48.954 D/OneSignal: Retrieved IAMs from DB redisplayedInAppMessages: []
2021-11-23 14:25:48.954 I/OneSignal: Last Pending Task has ran, shutting down
2021-11-23 14:25:48.956 D/OneSignal: OneSignal InAppMessageTracker initInfluencedTypeFromCache: OSChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}
2021-11-23 14:25:48.956 D/OneSignal: OneSignal NotificationTracker initInfluencedTypeFromCache: OSChannelTracker{tag=notification_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}
2021-11-23 14:25:48.959 D/OneSignal: OneSignal getUnattributedUniqueOutcomeEventsSentByChannel: []
2021-11-23 14:25:48.962 V/OneSignal: initWithContext called with: com.truckmap.truckmap.MainApplication@a6370f7
2021-11-23 14:25:48.962 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:25:48.963 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:25:48.964 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:25:48.964 W/System.err:     at com.onesignal.OneSignal.initWithContext(OneSignal.java:730)
2021-11-23 14:25:48.964 V/OneSignal: OneSignal SDK initialization delayed, waiting for remote params.
2021-11-23 14:25:48.966 D/OneSignal: Starting request to get Android parameters.
2021-11-23 14:25:48.969 D/OneSignal: OneSignalRestClient: Making request to: https://api.onesignal.com/apps/619bb485-4121-436c-97e2-660b16a18edd/android_params.js?player_id=6f107fca-b907-4a0a-b088-b6b6d55912fa
2021-11-23 14:25:48.972 I/OneSignal: Restoring notifications
2021-11-23 14:25:48.973 I/OneSignal: Querying DB for notifications to restore: created_time > 1637090748 AND dismissed = 0 AND opened = 0 AND is_summary = 0 AND expire_time > 1637695548
2021-11-23 14:25:48.976 D/OneSignal: OneSignalRestClient: Adding header if-none-match: W/"944cc3ca6795e6bde7af6e3b02efd6d7"
2021-11-23 14:25:49.288 V/OneSignal: OneSignalRestClient: After con.getResponseCode to: https://api.onesignal.com/apps/619bb485-4121-436c-97e2-660b16a18edd/android_params.js?player_id=6f107fca-b907-4a0a-b088-b6b6d55912fa
2021-11-23 14:25:49.290 D/OneSignal: OneSignalRestClient: GET - Using Cached response due to 304: {"awl_list":{},"android_sender_id":"184454251789","chnl_lst":[],"outcomes":{"direct":{"enabled":false},"indirect":{"notification_attribution":{"minutes_since_displayed":60,"limit":10},"enabled":false},"unattributed":{"enabled":false}},"receive_receipts_enable":false}
2021-11-23 14:25:49.293 D/OneSignal: OneSignal saveInfluenceParams: InfluenceParams{indirectNotificationAttributionWindow=60, notificationLimit=10, indirectIAMAttributionWindow=1440, iamLimit=10, directEnabled=false, indirectEnabled=false, unattributedEnabled=false}
2021-11-23 14:25:49.294 D/OneSignal: reassignDelayedInitParams with appContext: com.truckmap.truckmap.MainApplication@a6370f7
2021-11-23 14:25:49.294 V/OneSignal: setAppId called with id: 619bb485-4121-436c-97e2-660b16a18edd changing id from: null
2021-11-23 14:25:49.294 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:25:49.300 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignal.setAppId(OneSignal.java:692)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1136)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:844)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignal$6.complete(OneSignal.java:1077)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:206)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:151)
2021-11-23 14:25:49.301 W/System.err:     at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:283)
2021-11-23 14:25:49.306 D/OneSignal: OneSignal handleActivityLifecycleHandler inForeground: false
2021-11-23 14:25:49.324 D/OneSignal: initWithCachedInAppMessages: null
2021-11-23 14:25:49.324 D/OneSignal: doSessionInit on background with already registered user
2021-11-23 14:25:49.330 D/OneSignal: LocationController sendAndClearPromptHandlers from non prompt flow
2021-11-23 14:25:49.330 D/OneSignal: LocationController startGetLocation with lastLocation: null
2021-11-23 14:25:49.356 V/OneSignal: OneSignal SDK initialization done.
2021-11-23 14:25:49.357 D/OneSignal: startPendingTasks with task queue quantity: 0
2021-11-23 14:25:49.380 D/OneSignal: GMSLocationController GoogleApiClientListener onConnected lastLocation: null
2021-11-23 14:25:49.381 I/OneSignal: Device registered, push token = dxEZuuGyQ8mE87icA4uCxR:APA91bGJmTHjeBptxy5LbhyqeHiDy7Wh6AEiOxGgiXla38aAUwEG_RlwLvSyPwhBKVsaBt9I88jXkQVe5Qi2i_VZHWl0uYMUh01wTFqWU-xS90OkIWI2-GIlpHZNcRbGE89oZzzzoM25
2021-11-23 14:25:49.381 D/OneSignal: registerForPushToken completed with id: dxEZuuGyQ8mE87icA4uCxR:APA91bGJmTHjeBptxy5LbhyqeHiDy7Wh6AEiOxGgiXla38aAUwEG_RlwLvSyPwhBKVsaBt9I88jXkQVe5Qi2i_VZHWl0uYMUh01wTFqWU-xS90OkIWI2-GIlpHZNcRbGE89oZzzzoM25 status: 1
2021-11-23 14:25:49.385 D/OneSignal: registerUser:registerForPushFired:true, locationFired: false, remoteParams: com.onesignal.OneSignalRemoteParams$2@1101a58, appId: 619bb485-4121-436c-97e2-660b16a18edd
2021-11-23 14:25:49.385 D/OneSignal: registerUser not possible
2021-11-23 14:25:49.398 D/OneSignal: GMSLocationController GoogleApiClientListener lastLocation: null
2021-11-23 14:25:49.400 D/OneSignal: GMSLocationController GoogleApiClient requestLocationUpdates!
2021-11-23 14:25:57.645 D/OneSignal: ActivityLifecycleHandler runLostFocusLogic
2021-11-23 14:25:57.647 D/OneSignal: OSBackground sync, calling initWithContext
2021-11-23 14:25:57.649 V/OneSignal: initWithContext called with: com.onesignal.FocusDelaySyncJobService@3988404
2021-11-23 14:25:57.649 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:25:57.649 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:25:57.650 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:25:57.650 W/System.err:     at com.onesignal.OneSignal.initWithContext(OneSignal.java:730)
2021-11-23 14:25:57.651 D/OneSignal: OneSignal SDK initialization already completed.
2021-11-23 14:25:57.652 D/OneSignal: ActivityLifecycleHandler running AppFocusRunnable
2021-11-23 14:25:57.652 D/OneSignal: Application lost focus initDone: true
2021-11-23 14:25:57.652 D/OneSignal: Last session time set to: 1637695557652
2021-11-23 14:25:57.654 D/OneSignal: GMSLocationController onFocusChange!
2021-11-23 14:25:57.656 D/OneSignal: GMSLocationController GoogleApiClient requestLocationUpdates!
2021-11-23 14:25:57.657 W/OneSignal: FusedLocationApi.requestLocationUpdates failed!
    java.lang.NullPointerException: Calling thread must be a prepared Looper thread.
        at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source:11)
        at com.google.android.gms.internal.location.zzq.requestLocationUpdates(Unknown Source:6)
        at com.onesignal.GMSLocationController$FusedLocationApiWrapper.requestLocationUpdates(GMSLocationController.java:198)
        at com.onesignal.GMSLocationController$LocationUpdateListener.init(GMSLocationController.java:181)
        at com.onesignal.GMSLocationController$LocationUpdateListener.<init>(GMSLocationController.java:165)
        at com.onesignal.GMSLocationController.onFocusChange(GMSLocationController.java:117)
        at com.onesignal.LocationController.onFocusChange(LocationController.java:326)
        at com.onesignal.OneSignal.onAppLostFocus(OneSignal.java:1307)
        at com.onesignal.ActivityLifecycleHandler$AppFocusRunnable.run(ActivityLifecycleHandler.java:279)
        at java.lang.Thread.run(Thread.java:920)
2021-11-23 14:25:57.659 D/OneSignal: Application backgrounded focus time: null
2021-11-23 14:25:57.659 D/OneSignal: FocusTimeProcessorUnattributed:getUnsentActiveTime: 0
2021-11-23 14:25:57.660 D/OneSignal: FocusTimeProcessorUnattributed:sendUnsentTimeNow with time: 0 and influences: []
2021-11-23 14:25:57.660 D/OneSignal: FocusTimeProcessorUnattributed sendTime with: BACKGROUND
2021-11-23 14:25:57.660 D/OneSignal: FocusTimeProcessorUnattributed:getUnsentActiveTime: 0
2021-11-23 14:25:57.672 D/OneSignal: OneSignal scheduleSyncService unsyncedChanges: false
2021-11-23 14:25:57.674 D/OneSignal: LocationController scheduleUpdate lastTime: 350617 minTime: 600000
2021-11-23 14:25:57.674 V/OneSignal: OSSyncService scheduleLocationUpdateTask:delayMs: 249383
2021-11-23 14:25:57.675 V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:atTime: 249383
2021-11-23 14:25:57.680 I/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:result: 1
2021-11-23 14:25:57.680 D/OneSignal: OneSignal scheduleSyncService locationScheduled: true
2021-11-23 14:25:59.524 D/OneSignal: onActivityResumed: com.truckmap.truckmap.MainActivity@8a2a033
2021-11-23 14:25:59.524 D/OneSignal: curActivity is NOW: com.truckmap.truckmap.MainActivity:com.truckmap.truckmap.MainActivity@8a2a033
2021-11-23 14:25:59.524 D/OneSignal: ActivityLifecycleHandler handleFocus, with runnable: AppFocusRunnable{backgrounded=true, completed=true} nextResumeIsFirstActivity: true
2021-11-23 14:25:59.525 D/OneSignal: ActivityLifecycleHandler reset background state, call app focus
2021-11-23 14:25:59.525 D/OneSignal: Application on focus
2021-11-23 14:25:59.526 D/OneSignal: GMSLocationController onFocusChange!
2021-11-23 14:25:59.527 D/OneSignal: GMSLocationController GoogleApiClient requestLocationUpdates!
2021-11-23 14:25:59.529 D/OneSignal: Application foregrounded focus time: 112000757
2021-11-23 14:25:59.529 D/OneSignal: isPastOnSessionTime currentTimeMillis: 1637695559529 lastSessionTime: 1637695557652 difference: 1877
2021-11-23 14:25:59.529 D/OneSignal: Continue on same session with appEntryState: APP_OPEN
2021-11-23 14:25:59.529 D/OneSignal: OneSignal SessionManager attemptSessionUpgrade with entryAction: APP_OPEN
2021-11-23 14:25:59.529 D/OneSignal: OneSignal SessionManager attemptSessionUpgrade try UNATTRIBUTED to INDIRECT upgrade
2021-11-23 14:25:59.529 D/OneSignal: OneSignal ChannelTracker getLastReceivedIds lastChannelObjectReceived: []
2021-11-23 14:25:59.530 D/OneSignal: OneSignal ChannelTracker getLastReceivedIds lastChannelObjectReceived: []
2021-11-23 14:25:59.530 D/OneSignal: Trackers after update attempt: [OSChannelTracker{tag=notification_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}, OSChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}]
2021-11-23 14:25:59.530 D/OneSignal: OneSignal SessionManager sendSessionEndingWithInfluences with influences: []
2021-11-23 14:25:59.530 D/OneSignal: initWithCachedInAppMessages: null
2021-11-23 14:25:59.531 D/OneSignal: LocationController scheduleUpdate lastTime: 352475 minTime: 300000
2021-11-23 14:25:59.531 V/OneSignal: OSSyncService scheduleLocationUpdateTask:delayMs: -52475
2021-11-23 14:25:59.531 V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:atTime: 5000
2021-11-23 14:25:59.534 I/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:result: 1
2021-11-23 14:25:59.535 V/OneSignal: initWithContext called with: com.truckmap.truckmap.MainActivity@8a2a033
2021-11-23 14:25:59.535 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:25:59.535 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:25:59.536 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:25:59.536 W/System.err:     at com.onesignal.OneSignal.initWithContext(OneSignal.java:730)
2021-11-23 14:25:59.536 W/System.err:     at com.geektime.rnonesignalandroid.RNOneSignal.initOneSignal(RNOneSignal.java:182)
2021-11-23 14:25:59.536 W/System.err:     at com.geektime.rnonesignalandroid.RNOneSignal.onHostResume(RNOneSignal.java:755)
2021-11-23 14:25:59.537 D/OneSignal: OneSignal SDK initialization already completed.
2021-11-23 14:25:59.824 D/OneSignal: GMSLocationController onLocationChanged: Location[fused 39.142572,-86.545057 hAcc=19.064 et=+1d7h5m40s81ms alt=200.3754395909004 vAcc=3.0 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:26:19.373 W/OneSignal: Location permission exists but GoogleApiClient timed out. Maybe related to mismatch google-play aar versions.
2021-11-23 14:26:19.379 D/OneSignal: registerUser:registerForPushFired:true, locationFired: true, remoteParams: com.onesignal.OneSignalRemoteParams$2@1101a58, appId: 619bb485-4121-436c-97e2-660b16a18edd
2021-11-23 14:26:19.382 D/OneSignal: LocationController scheduleUpdate lastTime: 1 minTime: 300000
2021-11-23 14:26:19.382 V/OneSignal: OSSyncService scheduleLocationUpdateTask:delayMs: 299999
2021-11-23 14:26:19.382 V/OneSignal: OSSyncService scheduleSyncTask already update scheduled nextScheduledSyncTimeMs: 1637695564534
2021-11-23 14:26:19.412 D/OneSignal: registerUserTask calling readyToUpdate
2021-11-23 14:26:24.417 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: null
2021-11-23 14:26:32.726 D/OneSignal: OSBackground sync, calling initWithContext
2021-11-23 14:26:32.728 V/OneSignal: initWithContext called with: com.onesignal.SyncJobService@9a2c2df
2021-11-23 14:26:32.728 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:26:32.728 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:26:32.728 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:26:32.728 W/System.err:     at com.onesignal.OneSignal.initWithContext(OneSignal.java:730)
2021-11-23 14:26:32.729 D/OneSignal: OneSignal SDK initialization already completed.
2021-11-23 14:26:32.731 D/OneSignal: LocationController sendAndClearPromptHandlers from non prompt flow
2021-11-23 14:26:32.732 D/OneSignal: LocationController startGetLocation with lastLocation: Location[fused 39.142572,-86.545057 hAcc=19.064 et=+1d7h5m40s81ms alt=200.3754395909004 vAcc=3.0 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:26:32.744 D/OneSignal: GMSLocationController GoogleApiClientListener onConnected lastLocation: Location[fused 39.142572,-86.545057 hAcc=19.064 et=+1d7h5m40s81ms alt=200.3754395909004 vAcc=3.0 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:26:32.744 D/OneSignal: GMSLocationController GoogleApiClient requestLocationUpdates!
2021-11-23 14:26:32.768 D/OneSignal: GMSLocationController onLocationChanged: Location[fused 39.142381,-86.544970 hAcc=3.9 et=+1d7h7m13s876ms alt=200.02065430740902 vAcc=3.0 vel=0.003868914 sAcc=0.086023256 bear=327.7657 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:27:02.733 W/OneSignal: Location permission exists but GoogleApiClient timed out. Maybe related to mismatch google-play aar versions.
2021-11-23 14:27:02.737 D/OneSignal: LocationController scheduleUpdate lastTime: 0 minTime: 300000
2021-11-23 14:27:02.737 V/OneSignal: OSSyncService scheduleLocationUpdateTask:delayMs: 300000
2021-11-23 14:27:02.738 V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:atTime: 300000
2021-11-23 14:27:02.738 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: null
2021-11-23 14:27:02.740 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: {"app_id":"619bb485-4121-436c-97e2-660b16a18edd","device_os":"12","timezone":-18000,"timezone_id":"America\/New_York","language":"en","sdk":"040603","sdk_type":"react","android_package":"com.truckmap.truckmap.alpha","device_model":"Pixel 3","game_version":224,"net_type":0,"carrier":"Verizon","rooted":false,"loc_acc":15.145,"loc_type":1,"lat":39.1426008,"long":-86.545091,"loc_bg":true,"loc_time_stamp":1637694771347}
2021-11-23 14:27:02.740 V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob Scheduler already running!
2021-11-23 14:27:02.741 I/OneSignal: Error updating the user record because of the null user id
2021-11-23 14:27:02.742 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: {"app_id":"619bb485-4121-436c-97e2-660b16a18edd","device_os":"12","timezone":-18000,"timezone_id":"America\/New_York","language":"en","sdk":"040603","sdk_type":"react","android_package":"com.truckmap.truckmap.alpha","device_model":"Pixel 3","game_version":224,"net_type":0,"carrier":"Verizon","rooted":false,"loc_acc":15.145,"loc_type":1,"lat":39.1426008,"long":-86.545091,"loc_bg":true,"loc_time_stamp":1637694771347}
2021-11-23 14:27:02.743 I/OneSignal: Error updating the user record because of the null user id
2021-11-23 14:27:02.743 D/OneSignal: LollipopSyncRunnable:JobFinished needsJobReschedule: true
2021-11-23 14:28:03.205 D/OneSignal: OSBackground sync, calling initWithContext
2021-11-23 14:28:03.206 V/OneSignal: initWithContext called with: com.onesignal.SyncJobService@7bda75c
2021-11-23 14:28:03.206 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:28:03.206 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:28:03.207 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:28:03.207 W/System.err:     at com.onesignal.OneSignal.initWithContext(OneSignal.java:730)
2021-11-23 14:28:03.208 D/OneSignal: OneSignal SDK initialization already completed.
2021-11-23 14:28:03.209 D/OneSignal: LocationController sendAndClearPromptHandlers from non prompt flow
2021-11-23 14:28:03.211 D/OneSignal: LocationController startGetLocation with lastLocation: Location[fused 39.142381,-86.544970 hAcc=3.9 et=+1d7h7m13s876ms alt=200.02065430740902 vAcc=3.0 vel=0.003868914 sAcc=0.086023256 bear=327.7657 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:28:03.218 D/OneSignal: GMSLocationController GoogleApiClientListener onConnected lastLocation: Location[fused 39.142381,-86.544970 hAcc=3.9 et=+1d7h7m13s876ms alt=200.02065430740902 vAcc=3.0 vel=0.003868914 sAcc=0.086023256 bear=327.7657 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:28:03.218 D/OneSignal: GMSLocationController GoogleApiClient requestLocationUpdates!
2021-11-23 14:28:03.232 D/OneSignal: GMSLocationController onLocationChanged: Location[fused 39.142374,-86.544964 hAcc=9.648 et=+1d7h8m43s873ms alt=200.17077557294834 vAcc=3.0 vel=0.023531405 sAcc=0.086023256 bear=351.66644 {Bundle[EMPTY_PARCEL]}]
2021-11-23 14:28:33.212 W/OneSignal: Location permission exists but GoogleApiClient timed out. Maybe related to mismatch google-play aar versions.
2021-11-23 14:28:33.215 D/OneSignal: LocationController scheduleUpdate lastTime: 0 minTime: 300000
2021-11-23 14:28:33.215 V/OneSignal: OSSyncService scheduleLocationUpdateTask:delayMs: 300000
2021-11-23 14:28:33.216 V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob:atTime: 300000
2021-11-23 14:28:33.216 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: null
2021-11-23 14:28:33.217 V/OneSignal: OSBackgroundSync scheduleSyncServiceAsJob Scheduler already running!
2021-11-23 14:28:33.217 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: {"app_id":"619bb485-4121-436c-97e2-660b16a18edd","device_os":"12","timezone":-18000,"timezone_id":"America\/New_York","language":"en","sdk":"040603","sdk_type":"react","android_package":"com.truckmap.truckmap.alpha","device_model":"Pixel 3","game_version":224,"net_type":0,"carrier":"Verizon","rooted":false,"loc_acc":15.145,"loc_type":1,"lat":39.1426008,"long":-86.545091,"loc_bg":true,"loc_time_stamp":1637694771347}
2021-11-23 14:28:33.217 I/OneSignal: Error updating the user record because of the null user id
2021-11-23 14:28:33.218 D/OneSignal: UserStateSynchronizer internalSyncUserState from session call: false jsonBody: {"app_id":"619bb485-4121-436c-97e2-660b16a18edd","device_os":"12","timezone":-18000,"timezone_id":"America\/New_York","language":"en","sdk":"040603","sdk_type":"react","android_package":"com.truckmap.truckmap.alpha","device_model":"Pixel 3","game_version":224,"net_type":0,"carrier":"Verizon","rooted":false,"loc_acc":15.145,"loc_type":1,"lat":39.1426008,"long":-86.545091,"loc_bg":true,"loc_time_stamp":1637694771347}
2021-11-23 14:28:33.218 I/OneSignal: Error updating the user record because of the null user id
2021-11-23 14:28:33.218 D/OneSignal: LollipopSyncRunnable:JobFinished needsJobReschedule: true
...
...
2021-11-23 14:44:08.111 D/OneSignal: OSBackground sync, calling initWithContext
2021-11-23 14:44:08.112 V/OneSignal: initWithContext called with: com.onesignal.SyncJobService@fe58928
2021-11-23 14:44:08.113 V/OneSignal: Starting OneSignal initialization!
2021-11-23 14:44:08.113 V/OneSignal: Found class: .NotificationServiceExtension, attempting to call constructor
2021-11-23 14:44:08.114 W/System.err: java.lang.ClassNotFoundException: Invalid name: .NotificationServiceExtension
2021-11-23 14:44:08.114 W/System.err:     at java.lang.Class.classForName(Native Method)
2021-11-23 14:44:08.114 W/System.err:     at java.lang.Class.forName(Class.java:454)
2021-11-23 14:44:08.114 W/System.err:     at java.lang.Class.forName(Class.java:379)
2021-11-23 14:44:08.115 W/System.err:     at com.onesignal.OSNotificationController.setupNotificationServiceExtension(OSNotificationController.java:190)
2021-11-23 14:44:08.115 W/System.err:     at com.onesignal.OneSignal.init(OneSignal.java:774)
2021-11-23 14:44:08.115 W/System.err:     at com.onesignal.OneSignal.initWithContext(OneSignal.java:730)
2021-11-23 14:44:08.115 W/System.err:     at com.onesignal.OSBackgroundSync.doBackgroundSync(OSBackgroundSync.java:64)
2021-11-23 14:44:08.115 W/System.err:     at com.onesignal.SyncJobService.onStartJob(SyncJobService.java:40)
2021-11-23 14:44:08.115 W/System.err:     at android.app.job.JobService$1.onStartJob(JobService.java:62)
2021-11-23 14:44:08.115 W/System.err:     at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:105)
2021-11-23 14:44:08.115 W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
2021-11-23 14:44:08.115 W/System.err:     at android.os.Looper.loopOnce(Looper.java:201)
2021-11-23 14:44:08.115 W/System.err:     at android.os.Looper.loop(Looper.java:288)
2021-11-23 14:44:08.116 W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7842)
2021-11-23 14:44:08.116 W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2021-11-23 14:44:08.117 W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
2021-11-23 14:44:08.117 W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
2021-11-23 14:44:08.117 D/OneSignal: OneSignal SDK initialization already completed.

NotificationServiceExtension.java:

package com.truckmap.truckmap;

import android.content.Context;
import android.util.Log;
import org.json.JSONObject;

import com.onesignal.OSNotification;
import com.onesignal.OSMutableNotification;
import com.onesignal.OSNotificationReceivedEvent;
import com.onesignal.OneSignal.OSRemoteNotificationReceivedHandler;

import java.math.BigInteger;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;

@SuppressWarnings("unused")
public class NotificationServiceExtension implements OSRemoteNotificationReceivedHandler {

    @Override
    public void remoteNotificationReceived(Context context, OSNotificationReceivedEvent notificationReceivedEvent) {
        OSNotification notification = notificationReceivedEvent.getNotification();

        Log.i("OneSignalExample", "remoteNotificationReceived! " + notification);
        // Log.i("OneSignalExample", "Is app in focus? " + notificationReceivedEvent.getRawPayload().isAppInFocus);

        // Example of modifying the notification's accent color
        OSMutableNotification mutableNotification = notification.mutableCopy();
        mutableNotification.setExtender(builder -> {
            // Sets the accent color to Green on Android 5+ devices.
            // Accent color controls icon and action buttons on Android 5+. Accent color does not change app title on Android 10+
            builder.setColor(new BigInteger("FF00FF00", 16).intValue());
            // Sets the notification Title to Red
            Spannable spannableTitle = new SpannableString(notification.getTitle());
            spannableTitle.setSpan(new ForegroundColorSpan(Color.RED),0,notification.getTitle().length(),0);
            builder.setContentTitle(spannableTitle);
            // Sets the notification Body to Blue
            Spannable spannableBody = new SpannableString(notification.getBody());
            spannableBody.setSpan(new ForegroundColorSpan(Color.BLUE),0,notification.getBody().length(),0);
            builder.setContentText(spannableBody);
            //Force remove push from Notification Center after 30 seconds
            builder.setTimeoutAfter(30000);
            return builder;
        });
        JSONObject data = notification.getAdditionalData();
        Log.i("OneSignalExample", "Received Notification Data: " + data);

        // If complete isn't call within a time period of 25 seconds, OneSignal internal logic will show the original notification
        // To omit displaying a notification, pass `null` to complete()
        notificationReceivedEvent.complete(mutableNotification);
    }
}

AndroidManifest.xml:

<manifest android:targetSandboxVersion="1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.truckmap.truckmap"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

    <application
        android:name=".MainApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/launcher"
        android:roundIcon="@mipmap/launcher_round"
        android:allowBackup="false"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/notification_icon" />

        <meta-data 
            android:name="com.onesignal.NotificationServiceExtension"
            android:value=".NotificationServiceExtension" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:resizeableActivity="true"
            android:supportsPictureInPicture="true"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:windowSoftInputMode="adjustResize">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="geo" />
                <data android:scheme="truckmap" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:scheme="https"
                    android:host="truckmap.com"
                    android:pathPrefix="/place" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:scheme="https"
                    android:host="truckmap.com"
                    android:pathPrefix="/places" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:scheme="https"
                    android:host="truckmap.com"
                    android:pathPrefix="/route" />
            </intent-filter>
        </activity>

        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

        <service android:name=".TruckMapService" />

    </application>

</manifest>

So OneSignal Android SDK is attempting to call constructor, but a system error gets thrown right after. Sometimes it logs out specifically a ClassNotFoundException error.

Is there anything I can do to help debug this? Please let me know what other info I can provide! Thanks

jkasten2 commented 3 years ago

@sweatherall Thanks for reporting, it seems the OneSignal-Android-SDK is not correctly handling the dot class name shorthand naming.

If you fully namespace the class it should resolve your issue.

       <meta-data 
            android:name="com.onesignal.NotificationServiceExtension"
            android:value="com.truckmap.truckmap.NotificationServiceExtension" />
sweatherall commented 3 years ago

@jkasten2 wow thanks! That indeed fixed it!

I can see that OneSignal gets initialized now with no errors, however now I am receiving no feedback (no logcats) when I send a notification from the OneSignal dashboard, and I don't actually receive any notifications on device.

I will close this issue, but I'm wondering if anyone has any insight on what I can do to debug this new problem?