intercom_flutter icon indicating copy to clipboard operation
intercom_flutter copied to clipboard

Unhandled exception

Open yogikorke opened this issue 4 years ago • 21 comments

class io.intercom.com.bumptech.glide.load.engine.GlideException: Failed to load resource

above exception occurs sometimes.

yogikorke avatar Feb 18 '21 08:02 yogikorke

We experience the same error. Could this be the cause of our crash?

Caused by io.intercom.android.sdk.exceptions.IntercomIntegrationException
Intercom was not initialized correctly, Intercom.initialize() needs to be called in onCreate() in your Application class.
io.intercom.android.sdk.Injector.get

We do initialize Intercom, and the error doesn't always occur.

joknjokn avatar Mar 12 '21 09:03 joknjokn

On some android phones there is crash when opening intercom

Fatal Exception: java.lang.NoSuchMethodError No static method asAttributeSet(Ll/a/a/a;)Landroid/util/AttributeSet; in class Landroid/util/Xml; or its super classes (declaration of 'android.util.Xml' appears in /system/framework/framework.jar:classes2.dex)

androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates (ResourceManagerInternal.java) androidx.appcompat.widget.ResourceManagerInternal.addDelegate (ResourceManagerInternal.java) androidx.appcompat.widget.ResourceManagerInternal.addDelegate (ResourceManagerInternal.java) androidx.appcompat.widget.ResourceManagerInternal.checkVectorDrawableSetup (ResourceManagerInternal.java) androidx.appcompat.widget.ResourceManagerInternal.addDelegate (ResourceManagerInternal.java) androidx.appcompat.widget.AppCompatDrawableManager.access$000 (AppCompatDrawableManager.java) androidx.appcompat.widget.TintTypedArray.getDimensionPixelSize (TintTypedArray.java) androidx.appcompat.app.AppCompatDelegateImpl.addContentView (AppCompatDelegateImpl.java) androidx.appcompat.app.AppCompatDelegateImpl.ensureWindow (AppCompatDelegateImpl.java) androidx.appcompat.app.AppCompatDelegateImpl.addContentView (AppCompatDelegateImpl.java) androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java) io.intercom.android.sdk.activities.IntercomHelpCenterActivity.onCreate (IntercomHelpCenterActivity.java) <- Here is crash android.app.Activity.performCreate (Activity.java:6355) android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1108) android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2438) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2545) android.app.ActivityThread.access$1100 (ActivityThread.java:151) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1396) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:157) android.app.ActivityThread.main (ActivityThread.java:5601) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:774) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:652)

Yom3n avatar Mar 22 '21 12:03 Yom3n

@joknjokn , I have this problem. I was try to initial in different places, but it have the same problem, the plugin is crash at some times.

Caused by io.intercom.android.sdk.exceptions.IntercomIntegrationException
Intercom was not initialized correctly, Intercom.initialize() needs to be called in onCreate() in your Application class.

Are anybody known solution?

shtreb avatar Sep 30 '21 07:09 shtreb

Where are you initializing Intercom?

Zazo032 avatar Sep 30 '21 07:09 Zazo032

@Zazo032 I initialized in main() and after initialized and rendering all widgets, but it's not help. I can't reproduce the crash always

shtreb avatar Sep 30 '21 07:09 shtreb

I also have crash events in crashlytics on devices Galaxy A02s and Galaxy A10e.

Screenshot 2022-02-21 at 17 31 15

I initialize the intercom very early in the main function:

Future<void> main({
  FlypApiEnvironment environment = FlypApiEnvironment.production,
}) async {
  WidgetsFlutterBinding.ensureInitialized();
  AppConfiguration.init(environment: environment);
  await Firebase.initializeApp();

  registerWidgetGroups();
  FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
  await configureIntercom(environment);
  
  ....
  
    runZonedGuarded(
    () {
      runApp(
        ...
        ),
      );
    },
    FirebaseCrashlytics.instance.recordError,
  );
}

Future<void> configureIntercom(FlypApiEnvironment environment) async {
  await Intercom.initialize(
    environment.intercomAppId,
    iosApiKey: environment.intercomIosKey,
    androidApiKey: environment.intercomAndroidKey,
  );
}

I have 12 crash events in 5 days, can't reproduce them either.

TimYusR avatar Feb 21 '22 13:02 TimYusR

Per the docs, the initialize method in Android should be called in the onCreate method, but we're currently doing it on demand. Not sure when this was changed, neither if this is also an issue in the other platforms, but this might require some changes to how Android is initialized (maybe adding the android api key to the app's manifest and directly initialize in the onCreate method).

For reference, this is how it's done in React Native: https://developers.intercom.com/installing-intercom/docs/react-native-installation#initialize-intercom

Zazo032 avatar Feb 21 '22 13:02 Zazo032

@TimYusR which intercom_flutter version you are using?

deepak786 avatar Feb 28 '22 14:02 deepak786

@TimYusR which intercom_flutter version you are using?

I use intercom_flutter 5.3.0

TimYusR avatar Feb 28 '22 14:02 TimYusR

How did you declare this package in pubspec.yml? intercom_flutter: 5.3.0 or intercom_flutter: ^5.3.0?

deepak786 avatar Feb 28 '22 14:02 deepak786

How did you declare this package in pubspec.yml? intercom_flutter: 5.3.0 or intercom_flutter: ^5.3.0?

intercom_flutter: ^5.3.0

TimYusR avatar Feb 28 '22 14:02 TimYusR

I have a doubt that in intercom_flutter: 6.0.0, we added the receiver io.maido.intercom.PushInterceptReceiver which will automatically handle all the intercom messages (push, post, etc.). So maybe before Flutter's main method, this receiver gets called and results in the crash of "intercom was not initialized correctly".

@Zazo032 what do you think?

if this happens on earlier versions also then it must be something else. We need a reproducible sample.

deepak786 avatar Feb 28 '22 14:02 deepak786

Could be, since seem to be difficult to reproduce, we'll need more specific details on the conditions when the crash occurs

Zazo032 avatar Feb 28 '22 14:02 Zazo032

I checked there is no issue in receiver io.maido.intercom.PushInterceptReceiver. This receiver uses only IntercomPushClient().

If we use Intercom.client() before initializing the Intercom then this error appears. Mostly all of the APIs such as Intercom.displayMessenger, Intercom.displayCarousel(id), etc are using the Intercom.client()

Intercom.initialize is being called in the main method so I'm not sure what is the cause of this error. Maybe we can try to initialize the Intercom in onAttachedToEngine by saving the AppId and corresponding keys in SharedPrefs, for e.g. But first, need a reproduction of the issue so that it can be tested with the above solution.

deepak786 avatar Mar 10 '22 12:03 deepak786

@TimYusR Please check that your code is not calling any other Intercom API before the initialize. Maybe there are places such as background handlers where you might be calling the Intercom APIs.

deepak786 avatar Mar 10 '22 12:03 deepak786

I am having the same issue.

I am calling Intercom.instance.initialize(appId, androidApiKey, iosApiKey) inside the main() function in main.dart. I am sure I don't have any other places when I am calling Intercom API, as I only call it on one button press.

Did you find out how to work around the issue? Can I somehow manually call initialisation inside the Android?

dCubelic avatar May 10 '22 10:05 dCubelic

@TimYusR Please check that your code is not calling any other Intercom API before the initialize. Maybe there are places such as background handlers where you might be calling the Intercom APIs.

I don't use any other Intercom API before initialization as @dCubelic

TimYusR avatar May 11 '22 07:05 TimYusR

@deepak786 this problem appears for Android devices

TimYusR avatar May 11 '22 07:05 TimYusR

I don't know if there is a way to inject the code into the Android Application class. Do you know any similar package which also requires the SDK to be initialized in the onCreate of the Android application? This would help. By the way, I asked this in the Flutter https://github.com/flutter/flutter/issues/103709

deepak786 avatar May 13 '22 15:05 deepak786

I'm having the same issue and all the crashes I have on my app are coming from this error.

From what I saw on stackoverflow, these are some packages which are started on the background:

gfb-47 avatar Jul 13 '22 12:07 gfb-47

Are there any updates on this issue?

TimYusR avatar Oct 12 '22 12:10 TimYusR

Any update on this? We are using the latest version of this library and still facing this issue.

nikb7 avatar Mar 20 '23 05:03 nikb7

A way has been added in the latest version intercom_flutter: 7.6.8

Follow the documentation here https://pub.dev/packages/intercom_flutter#android starting with the section According to the documentation, Intercom must be initialized in the Application onCreate. So follow the below steps to achieve the same:

Let me know if there is any doubt.

By the way, don't hesitate to buy me a coffee https://www.buymeacoffee.com/deepakdroid :)

deepak786 avatar Mar 29 '23 16:03 deepak786

We are initializing Intercom in Application onCreate but yet see this crash happening from Crashlytics. Any ideas if it could be related to flow where user opens Intercom push notification and app instance is not alive or something like that?

nikorehnback avatar Jun 19 '24 02:06 nikorehnback