cmaycumber / config-plugin-react-native-intercom

Expo plugin for adding @intercom/react-native-intercom using expo config plugins
74 stars 38 forks source link

Intercom is not initialized on android #38

Closed Arhane closed 1 year ago

Arhane commented 1 year ago

Problem:

Using Intercom on android I get the error message

Error: java.lang.IllegalStateException: Please call Intercom.initialize() before requesting the client.

Details

Everything seems fine with internals of the android part of app I build the android folder with expo prebuild -p android and checked the contents of the MainApplication.java At the file start

package com.mayd.rider;
import com.intercom.reactnative.IntercomModule;

and onCreate method

@Override
  public void onCreate() {
    super.onCreate();
    // If you opted-in for the New Architecture, we enable the TurboModule system
    ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
    SoLoader.init(this, /* native exopackage */ false);
    IntercomModule.initialize(this, "secret", "secret");

    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
    ApplicationLifecycleDispatcher.onApplicationCreate(this);
  }

I run my application with eas build --platform android and create an expo server with expo start --dev-client

Arhane commented 1 year ago

TL;DR The problem was eas and environment variables

The problem was with the environment variables. I loaded them with dotenv and used them like process.env.INTERCOM_IOS_AUTH_TOKEN in app.config.js. But when I ran the build locally, the build was happening in another folder and didn't have access to environment variables

MorenoMdz commented 1 year ago

TL;DR The problem was eas and environment variables

The problem was with the environment variables. I loaded them with dotenv and used them like process.env.INTERCOM_IOS_AUTH_TOKEN in app.config.js. But when I ran the build locally, the build was happening in another folder and didn't have access to environment variables

Interesting, I might be having the same issue, when you say it is running in a different folder how did you solve it?

elmaxe commented 1 year ago

We had the same issue previously (around October 2022). process.env.INTERCOM_ANDROID_TOKEN in app.config.js, but no secrets configured at expo.dev, so when it built at Expo's servers it didn't have access to the correct variables, and intercom couldn't be initialized.