customerio / customerio-flutter

Flutter plugin for Customer.io
https://www.customer.io/docs/sdk/flutter/getting-started/
MIT License
12 stars 10 forks source link

iOS runtime error: "The 'customer_io' channel sent a message from native to Flutter on a non-platform thread." #126

Closed lukemmtt closed 2 months ago

lukemmtt commented 4 months ago

I'm getting this error in the console when running my Flutter iOS build. The full message reads:

[ERROR:flutter/shell/common/shell.cc(1055)] The 'customer_io' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.

It's the same message reported in https://github.com/customerio/customerio-flutter/issues/95 (closed unresolved) and https://github.com/customerio/customerio-flutter/issues/121 (closed after the reporter identified a solution).

Notably in #121, the OP reported that he was getting the error in the iOS Simulator (as I am, in addition to debug builds on physical devices), but the solution for him (and others) seemed to be "upgrading Gradle to 7.4.1". I've done similarly (i.e. upgraded Gradle to the latest 7.x release, Gradle 7.4.2), but it hasn't resolved my issue, and furthermore, I'm perplexed as to how it could—to my understanding, Gradle has nothing to do with iOS builds.

I'd appreciate any pointers or clarification. Thanks!

levibostian commented 4 months ago

Thanks for contacting us, Luke. Sorry to hear you are experiencing this.

In your app, are you able to reproduce this error in the console? As in, you are able to perform a series of steps in your app to make this error occur? If so, could you please share with us those steps that you're performing? The more detail the better.

I do understand how the gradle suggestions may not be related to this error you're having. Hopefully from a better understanding of how you're able to trigger this error, we can pinpoint why this is happening in your app.

Have a great rest of your day!

lukemmtt commented 2 months ago

Thanks for the reply @levibostian , and sorry for the delay in responding. I have not been making use of Customer.io recently, so this hasn't been a pressing priority. Now I'm looking to finally make use of the platform, and I'm getting reacquainted with the Customer.io SDK and this issue.

To answer your questions: Yes, the error is reproducible in my environment. It appears on every fresh install of a debug build, in both the iOS simulator (iPhone 15 iOS 17.5) and on my physical device (iPhone 12 mini iOS 17.5). It also often appears even when I simply "run" the app on iOS via the Android Studio (overwriting an existing install), but for some reason it appears less consistently on these non-fresh-installs.

Notably, I have only seen the issue in the console (i.e. running debug builds)—I haven't seen any errors reported by my error reporting tools (Crashlytics and Sentry), although I suspect this could be because Customer.io SDK is initialized very early in my app's launch sequence, concurrently with the initialization of my error reporting SDKs, and thus perhaps it is occurring in prod just as well, but simply not being logged & reported.

Additional Environment details:

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/lukemt/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/lukemt/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2

[✓] Android Studio (version 2024.1) • Android Studio at /Users/lukemt/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.91.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.92.0

[✓] Connected device (5 available) • Luke M iPad (mobile) • 00008103-001E30611ED3001E • ios • iOS 18.0 22A5307f • LM iPhone (mobile) • 00008101-000A79601A08001E • ios • iOS 17.5.1 21F90 • iPhone 15 (mobile) • 7E6C3AC0-7477-432D-B767-548E5E02693F • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources • All expected network resources are available.

levibostian commented 2 months ago

Thank you for all of that information. Greatly appreciate it!

I'm talking with my team about this issue. I'll update you on this issue with what we come up with.

Glad to hear that you're looking to use Customer.io more 🙂. We hope you have a wonderful experience!

Have a great rest of your day.

lukemmtt commented 2 months ago

Glad to hear it, thanks for the follow up and for looking into this!

Adenugakolade-02 commented 2 months ago

Hello, I am currently facing this issue also running on my IOS simulator.

image

levibostian commented 2 months ago

@lukemmtt, if you have a moment, I have a build of the SDK that could benefit from testing.

To install the build, edit your pubspec.yaml to install the SDK from github branch:

dependencies:
  customer_io:
    git:
      url: https://github.com/customerio/customerio-flutter.git
      ref: levi/customer_io-channel-non-native-thread

Then, run your app as you have been to try and reproduce the error. See if the error continues to show up.

Note: We do not suggest shipping your app to production with a non-production version of the SDK. Debug app builds are suggested.

We greatly appreciate working with us to resolve this issue.

lukemmtt commented 2 months ago

Glad to try that, thanks for the attention to this! I'll let you know shortly.

lukemmtt commented 2 months ago

Just loaded a fresh install debug build on my physical iPhone 12 mini with that SDK ref, and the issue appears to be resolved. Thank you Levi!

levibostian commented 2 months ago

Thanks for your continued support everyone.

Version 1.5.1 of the Flutter SDK has been deployed and includes a fix for this error message.

Please, give this new release a try. If you continue to receive this error message after install, send us a message with updated reproduction steps and we'll continue to look into it.

Thank you so much!