customerio / customerio-reactnative

MIT License
23 stars 11 forks source link

Working with Intercom and CIO on Expo #271

Closed beqramo closed 1 month ago

beqramo commented 1 month ago

Hi, We are trying to move from React native CLI to Expo and I'm trying to configure things as it was but not the same final code that was working on previous project now it doesn't work anymore.

I followed previous issue solution that I'm author of: https://github.com/customerio/customerio-reactnative/issues/120 but now it doesn't work anymore.

SDK version:

    "customerio-expo-plugin": "^1.0.0-beta.15",
    "customerio-reactnative": "^3.7.0",
    "expo": "~51.0.12",
    "react-native": "0.74.2",
   "@intercom/intercom-react-native": "^7.1.2",

google services version on android(I was forced to update as other packages were not working well, I don't think these things are connected though):

        classpath 'com.google.gms:google-services:4.4.1'

Environment: Development

Error:


> Task :app:compileDebugJavaWithJavac FAILED
/Users/*/android/app/src/main/java/com/geraldwallet/MainNotificationService.java:8: error: cannot find symbol
import io.customer.messagingpush.CustomerIOFirebaseMessagingService;
                                ^
  symbol:   class CustomerIOFirebaseMessagingService
  location: package io.customer.messagingpush
/Users/*/android/app/src/main/java/com/geraldwallet/MainNotificationService.java:15: error: package CustomerIOFirebaseMessagingService does not exist
    CustomerIOFirebaseMessagingService.Companion.onNewToken(getApplication(), refreshedToken);
                                      ^
/Users/*/android/app/src/main/java/com/geraldwallet/MainNotificationService.java:20: error: package CustomerIOFirebaseMessagingService does not exist
  boolean didCustomerIOHandlePush = CustomerIOFirebaseMessagingService.Companion.onMessageReceived(getApplication(), remoteMessage);
mrehan27 commented 1 month ago

Hey @beqramo. Thanks for reaching out and sharing the details. We haven't enforced any requirement for newer Google Services libraries. However, starting from 3.7.0, Android apps should be compatible with Gradle 8. Since you have already shared that you are using React Native 0.74.2, it is fully compatible with Gradle 8 and shouldn't be an issue for you.

For the error you are facing, it looks like your app is unable to find the required package and might need updates in build.gradle file. Before I suggest the workaround, can you please confirm if you have tried any of the solutions listed here and if they worked for you? It should be easier for you to manage. If none of them works, can you please share the reason so we can note it down for future improvements?

If the above solutions don't work for you and you want to continue using the older solution, can you try updating your build.gradle file as suggested here? Once you update and clean build your project, it should be able to find the required package and classes. Also, the method now has @JvmStatic annotation added, so you don't need to call with Companion object. You can directly call the method from Java class as follows:

import io.customer.messagingpush.CustomerIOFirebaseMessagingService;

CustomerIOFirebaseMessagingService.onNewToken(getApplication(), refreshedToken);
CustomerIOFirebaseMessagingService.onMessageReceived(getApplication(), remoteMessage);

Do let me know if this doesn't help or if you have more questions.

beqramo commented 1 month ago

Hi, thanks for your quick answer @mrehan27 , about suggested/recomended solutions: 1st solution: I'm using CIO as my main "notification manager" so I don't have any other way to get the token. 2nd solution: well in that case it will not work for the Intercom as I will not have a way to give token to itnercom on native side.

about the solution: adding bellow codes was the solution.

 implementation "io.customer.android:tracking"
    implementation "io.customer.android:messaging-push-fcm"
    implementation "io.customer.android:messaging-in-app"

thanks

mrehan27 commented 1 month ago

Thanks for the confirmation @beqramo. I'll note down the feedback internally. Glad the solution worked for you.

In case you haven't noticed this before, you can also set token directly from your JavaScript code by fetching it from any other library like Intercom or others, as this will help you reduce your project's direct dependency on native libraries. However, if you want to continue using native methods directly, you can continue using them.

Also, please note that this isn't the ideal approach, as we want customers to interact mostly with React Native package directly and not the native dependencies. However, I understand the current solutions in React Native package don’t solve the problem for you, so it's completely fine to use native methods at the moment.

Since the issue is resolved, I'm closing this ticket. Even if the issue is closed, please feel free to ask any more questions you have. Have a great day!