wix / react-native-notifications

React Native Notifications
MIT License
3.23k stars 763 forks source link

error: cannot find symbol FirebaseMessaging.getInstance().getToken() on android build #925

Closed MarlonAEC closed 1 year ago

MarlonAEC commented 1 year ago

Hi I recently updated firebase libraries (app, crashlytics, core... etc), to the latest version, and my android App started crashing and closing. On Crashlytics I was able to identify this error:

Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
com.wix.reactnativenotifications.fcm.FcmToken.refreshToken (FcmToken.java:78)
com.wix.reactnativenotifications.fcm.FcmToken.onAppReady (FcmToken.java:68)
com.wix.reactnativenotifications.fcm.FcmInstanceIdRefreshHandlerService.onHandleWork (FcmInstanceIdRefreshHandlerService.java:26)
androidx.core.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:396)
androidx.core.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:387)
android.os.AsyncTask$3.call (AsyncTask.java:394)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
java.lang.Thread.run (Thread.java:923)

I thought it was due to the version of react-native-notifications being to old since we were using 3.4.2 so I decided to update to the latest but then my android build failed with this error:

.../node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmToken.java:75: error: cannot find symbol
        FirebaseMessaging.getInstance().getToken()
                                       ^
  symbol:   method getToken()
  location: class FirebaseMessaging
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

code base on my end anything changed :( this is my environment: targetSDKVersion: 30 compileSDKVersion: 33 minSDKVersion: 24 React Native: 66.5 firebase/app: 16.4.6 firebase/crashlytics: 16.4.6

Let me know if you need more info about it but so far I couldn't find what could have caused the issue. Thanks in advance for the help!

MarlonAEC commented 1 year ago

If someone finds this (even myself lol) I was able to fix it with this configuration: compileSdkVersion: 33 buildToolsVersion: 28.0.3 react-native-notifications: 4.3.3 targetSdkVersion: 30 (cannot target higher due to our tech debt) Also, I had to add this to android/app/build.gradle

    implementation "com.google.firebase:firebase-core:21.1.0"
    implementation "com.google.firebase:firebase-messaging:21.1.0"
    implementation "com.google.firebase:firebase-appindexing:17.1.0"
    implementation 'com.google.firebase:firebase-analytics:21.1.0'
    implementation "com.google.android.gms:play-services-base:16.0.0"
    implementation "com.google.firebase:firebase-iid:21.1.0" //apparently this one was the one that helped the most

and this to android/build.gradle

     firebaseVersion = "21.1.0"
     firebaseMessagingVersion = "21.1.0" // Used by react-native-push-notification

You don't need to add them all just the ones you are using in your project (maybe you use different firebase libraries) After I added those then my IOS build started crashing for other reasons also related to this so after the whole update process I ended up Updating the OS version of my VM in my pipeline to MacOS-12 in order to use XCode 14 in my build process (since it comes by default installed in this OS version) and also this StackOverflow post help me a lot with some other errors due to sign-in issues after the update. Hope that helps someone and yes you can close this issue if you think is not relevant anymore. Thanks!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 1 year ago

The issue has been closed for inactivity.