tinycreative / react-native-intercom

React Native wrapper for Intercom.io
MIT License
406 stars 280 forks source link

Native module IntercomWrapper tried to override IntercomModule. #329

Closed anthonycaron closed 2 years ago

anthonycaron commented 4 years ago

I followed all the instructions described in the installation guide: https://github.com/tinycreative/react-native-intercom/blob/master/README.md

Then I tried to run the app on my Android device and I'm having the following error: Native module IntercomWrapper tried to override IntercomModule. Check the getPackages() method in MainApplication.java, it might be that module is created twice. If this was your intention, set canOverrideExistingModule=true

I double checked and I haven't imported twice the same package.

Here's the content of my getPackages() method:

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      packages.add(new RNFirebaseMessagingPackage());
      packages.add(new RNFirebaseAnalyticsPackage());
      packages.add(new RNFirebaseNotificationsPackage());
      packages.add(new ReactVideoPackage());
      packages.add(new IntercomPackage());
      return packages;
    }

When removing the import of IntercomPackage from the getPackages() method, it does launch my app without issues, so it is related to this import but I'm not sure what's going on here.

Any help would be appreciated, thanks !

anthonycaron commented 4 years ago

Alright, so I found how to solve this and I basically followed what was advised in the warning I got. I created a PR, if anybody runs into the same issue then maybe it will help you too.

StijnCoolen commented 4 years ago

I also experience this issue. Somehow new IntercomPackage() andIntercom.initialize() are conflicting.

avirefundit commented 4 years ago

@anthonycaron @StijnCoolen what is a version of react-native do you use? If it a react-native version 0.60+ with auto-linking then it is really twice. The first one auto-linking does and the second you do with packages.add(new IntercomPackage());.

I've managed to run this package on RN 0.61.5 only after excluding it from auto-linking (android) via react-native.config.js

dependencies: {
        'react-native-intercom': {
            platforms: {
                android: null
            }
        }
}

And then link the package manually as we did before RN 0.60, otherwise it just not working. On iOS it works as expected.

Manually linking on android (old way)

// settings.gradle
include ':react-native-intercom'
project(':react-native-intercom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-intercom/android')
// app/build.gradle
dependencies {
// ... other dependencies
implementation 'io.intercom.android:intercom-sdk-base:5.+'
implementation project(':react-native-intercom')
}
// MainApplication.java
// do not forget to import
import com.robinpowered.react.Intercom.IntercomPackage;
import io.intercom.android.sdk.Intercom;

// Add package
packages.add(new IntercomPackage());
StijnCoolen commented 4 years ago

@avirefundit we're on 0.60.4, do you think I need to exclude Intercom from auto-linking?

avirefundit commented 4 years ago

@avirefundit we're on 0.60.4, do you think I need to exclude Intercom from auto-linking?

@StijnCoolen if it works for you, then you can leave it there. It just didn't work for me.

ymcewen commented 4 years ago

Hi Guys. I was having the same issue as the original poster. I followed the unlinking instructions and it now "works", however as soon as I call Intercom.registerIdentifiedUser({ userId: 'bob' }); (for example), it creates/updates the user, but then it crashes. Constantly. The only way to get it open again is to delete and re-run.

Unfortunately the crash disappears as soon as I try to get more details, so not able to say exactly what the error is (and nothing is logged to the console or terminal). The error does make reference to an invalid color in io.intercom... but that's all I really see in the split second it stays open.

Do you have any suggestions?

Many thanks in advance!