Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation: Channel communication fails on iOS when integrating Turn-by-Turn navigation into a larger app #211

Open
yehuda-noiman opened this issue Nov 11, 2024 · 5 comments
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@yehuda-noiman
Copy link

Environment details

  1. Flutter version 3.24.3, stable channel
  2. sonama 14.5, intel
  3. google_navigation_flutter: ^0.3.0
    OS type and version: iOS iOS 16.7.10 but reproduced at any IOS we tried
    Library version and other environment information:
    Flutter version: 3.22.1 • channel stable
    google_navigation_flutter version: 0.3.0

Device model: (IPhone 8 plus, iPhone 12 Pro Max, more IOS devices)
Steps to reproduce
Integrate the google_navigation_flutter plugin into a large existing Flutter app.
Implement the Turn-by-Turn navigation feature using code from the example app.
Run the app on an iOS device or simulator.
Attempt to start Turn-by-Turn navigation.
Observe that the app fails due to channel communication issues.
Expected behavior
The Turn-by-Turn navigation should start and function as expected, just like it does in the example app provided by the google_navigation_flutter plugin.
Actual behavior
When attempting to start Turn-by-Turn navigation in the larger app, the app fails on channel communication. Specifically, the response in the onNavInfo function is nil, leading to a failure in the completion handler.
from messages.g.swift
/// Turn-by-Turn navigation events.

func onNavInfo(navInfo navInfoArg: NavInfoDto,
               completion: @escaping (Result<Void, FlutterError>) -> Void) {
    let channelName =
      "dev.flutter.pigeon.google_navigation_flutter.NavigationSessionEventApi.onNavInfo"
    let channel = FlutterBasicMessageChannel(
      name: channelName,
      binaryMessenger: binaryMessenger,
      codec: codec
    )
    channel.sendMessage([navInfoArg] as [Any?]) { response in
        guard let listResponse = response as? [Any?] else {
            // The code goes here and the response is nil
            completion(.failure(createConnectionError(withChannelName: channelName)))
            return
        }
        if listResponse.count > 1 {
            let code: String = listResponse[0] as! String
            let message: String? = nilOrValue(listResponse[1])
            let details: String? = nilOrValue(listResponse[2])
            completion(.failure(FlutterError(code: code, message: message, details: details)))
        } else {
            completion(.success(()))
        }
    }
}

Note: The comment // The code goes here and the response is nil indicates where the response is unexpectedly nil.
Note2: The simulator works it's just that we don't get any events on the dart side

Additional Information:
The Turn-by-Turn navigation works as expected when using the example app provided by the plugin.
The issue only occurs when integrating the same code into a larger app.
There might be a discrepancy in how the message channels are set up or how the binary messenger communicates in a larger app context.
Please let me know if you'd like to add anything else or need further assistance!

@yehuda-noiman yehuda-noiman added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 11, 2024
@jokerttu jokerttu added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed triage me I really want to be triaged. labels Nov 12, 2024
@jokerttu
Copy link
Contributor

Hi @yehuda-noiman,
Thank you for reporting this issue.

To help us reproduce it, could you provide more details about the app context that’s causing the problem? If possible, sharing a partial implementation of your application that demonstrates the issue would be very helpful.

You can add a breakpoint at this line and verify that navInfo is properly handled and converted for the channel.

@yehuda-noiman
Copy link
Author

hi
the app is quite large
things to NOTE

we are using many plugins and packages (ill send here the pubspec)
as i said, it also failed when i copy pasted the turn_by_turn example in our project
another thing note:
before using this plugin we developed the plugin in house and the navigation and turn by turn worked, we just had some crashes from time to time so we decided to use the official plugin...

our pubspec.yaml

`name: courier_flutter
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.


version: 2.1.26+2011385


 
environment:
  sdk: ">=3.0.0 <4.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.



dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.5

  ##### presentation #####

  # flutter_google_navigation_ux:
  #   # path: /Users/yehuda/development/NavigationPluginFlutter/flutter_google_navigation_ux
  #   git:
  #     url: "[email protected]:getpackageltd/NavigationPluginFlutter.git"
  #     #   url: "https://github.com/getpackageltd/NavigationPluginFlutter.git"
  #     ref: "main"
  #     path: "flutter_google_navigation_ux"

  flutter_bloc: ^8.1.1
  bloc_concurrency: ^0.2.5
  intl_phone_number_input: ^0.7.1
  pinput: ^5.0.0
  smart_auth: ^2.0.0
  intl: ^0.19.0
  cached_network_image: ^3.2.2
  flutter_animate: ^3.1.0
  country_icons: ^2.0.2
  dropdown_button2: ^2.3.9
  flutter_keyboard_visibility: ^5.4.0
  bottom_inset_observer: ^3.1.0
  flutter_svg: ^1.1.6
  inview_notifier_list: ^3.0.0
  flutter_callkit_incoming: ^2.0.0+1
  appsflyer_sdk: ^6.13.0+2
  mutex: ^3.1.0
  # date_utils: ^0.2.0
  camera: ^0.10.5+9
  flutter_countdown_timer: ^4.1.0
  google_fonts: ^4.0.4
  url_launcher: ^6.1.11
  blur: ^3.1.0
  modal_bottom_sheet: ^3.0.0-pre
  
  open_store: ^0.4.0
  transparent_image: ^2.0.0
  draggable_bottom_sheet: ^1.0.2
  toggle_switch: ^2.0.1
  snapping_sheet:
    path: ./snapping_sheet-3.1.0
  flutter_reorderable_list: ^1.2.0
  flutter_expandable_fab: ^1.6.1
  flutter_smartlook: ^4.1.23
  # flutter_map: ^3.1.0
  livechatt: "^1.4.0"
  onesignal_flutter: ^5.1.2
  flutter_advanced_switch: ^3.0.1
  flutter_slidable: ^3.1.0
  slide_switcher: ^1.1.2
  mobile_scanner: ^3.3.0
  hand_signature: ^3.0.1
  internet_connection_checker: ^1.0.0+1
  flutter_screenutil: ^5.7.0
  device_preview:
    git:
      url: "https://github.com/RuslanTsitser/flutter_device_preview.git"
      ref: "master"
      path: "device_preview"
  fl_chart: ^0.62.0
  image: ^3.2.2
  slide_countdown: ^0.5.0
  flutter_easyloading: ^3.0.5
  easy_rich_text: ^1.2.0
  flutter_image_compress: ^2.2.0
  gif: ^2.3.0
  flutter_localizations:
    sdk: flutter
  searchable_listview: ^2.4.0
  pdfx: ^2.6.0
  # pdfx:
  #   git:
  #     url: "https://github.com/getpackageltd/packages.flutter_pdfx.git"
  #     ref: "main"
  #     path: "packages/pdfx"

  ##### core #####
  firebase_remote_config: ^5.0.3
  maps_toolkit: ^2.0.1
  firebase_core: ^3.2.0
  google_static_maps_controller: ^1.0.0
  flutter_polyline_points: ^2.0.0
  flutter_local_notifications: ^15.0.0
  firebase_storage: ^12.1.1
  firebase_messaging: ^15.0.3
  firebase_analytics: ^11.2.0
  # awesome_notifications: ^0.7.4+1
  # awesome_notifications_fcm: ^0.7.4+1
  google_polyline_algorithm: ^3.1.0
  visibility_detector: ^0.4.0+2
  go_router: ^10.0.0
  flutter_google_maps_webservices: ^1.1.1
  shared_preferences: ^2.2.0
  share_plus: ^7.2.1
  sprintf: ^7.0.0
  logger: ^2.0.2+1
  device_info_plus: ^9.0.3
  isar: 3.1.0+1
  isar_flutter_libs: 3.1.0+1
  hive: ^2.2.3
  sentry_flutter: ^7.12.0
  sembast: ^3.6.0
  either_dart: ^0.2.0
  wakelock:
    git:
      url: "[email protected]:yehuda-noiman/wakelock.git"
      ref: "main"
      path: "wakelock"
  lottie: 2.0.0 # use latest after migrating to dart 3.0 (Because courier_flutter depends on lottie >=2.4.0 which requires SDK version ^3.0.0, version solving failed.)

  injectable: ^1.5.3
  get_it: ^7.2.0
  graphql: ^5.1.3
  fresh_graphql: ^0.6.0
  flutter_secure_storage: ^8.0.0

  collection: ^1.16.0
  jwt_decoder: ^2.0.1
  equatable: ^2.0.5
  enum_to_string: ^2.0.1
  auto_size_text: ^3.0.0
  phone_state: ^1.0.3
  # flutter_background_geolocation: ^4.13.5
  google_mlkit_face_detection: ^0.7.0
  tflite_flutter: ^0.10.1
  google_api_headers: ^2.0.3
  # google_maps_flutter: ^2.2.0
  google_maps_flutter:
    path: ./google_maps_flutter
  geolocator: ^13.0.1
  internet_file:
    git:
      url: "https://github.com/ScerIO/packages.dart.git"
      ref: "master"
      path: "packages/internet_file"
  datadog_flutter_plugin: ^2.4.0
  gql_dio_link: ^1.0.0
  pretty_dio_logger: ^1.3.1
  dio: ^5.2.1+1
  image_picker: ^1.0.1
  # background_location_tracker: ^1.4.0
  permission_handler: ^10.4.3
  background_locator_2:
    #  path: /Users/yehuda/development/background-locator
    git:
      url: "[email protected]:getpackageltd/getpackage-background-locator.git"
      #   url: "https://github.com/getpackageltd/NavigationPluginFlutter.git"
      ref: "main"

  path_provider: ^2.0.15
  google_navigation_flutter: ^0.4.0

dev_dependencies:
  integration_test:
    sdk: flutter
  flutter_test:
    sdk: flutter
  flutter_driver:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0
  go_router_builder: any
  faker: ^2.1.0
  # flutter_foreground_task: ^3.10.0
  isar_generator: 3.1.0+1
  change_app_package_name: ^1.1.0
  bloc_test: ^9.1.0
  graphql_codegen: ^0.13.0
  build_runner: ^2.1.8
  injectable_generator: ^1.5.4
  json_serializable: ^6.5.3
  mockito: ^5.3.2
  icons_launcher: ^2.0.5
  flutter_native_splash: ^2.2.16
  mocktail: ^0.3.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
icons_launcher:
  image_path: "assets/images/store_logo.png"
  platforms:
    android:
      enable: true
    ios:
      enable: true
# The following section is specific to Flutter packages.
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  # generate: true
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - lib/l10n/
    - assets/images/
    - assets/backgrounds/
    - assets/icons/svg/
    - assets/mobilefacenet.tflite
    - assets/lottie_anim/
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

it might be something to do with pigeon...
we have alot of users in production using the app and we would really appreciate your assistance.
thanks

@yehuda-noiman
Copy link
Author

and as per where you told me to put a break point i already checked and it only fails at the messages.g.dart when using the channel to send the message to the dart side, meaning the issue is not there.

@jokerttu
Copy link
Contributor

Hi @yehuda-noiman

This issue is indeed unusual, and I have not been able to reproduce it so far.

I noticed that you are using the following package:

  google_maps_flutter:
    path: ./google_maps_flutter

As both google_maps_flutter and google_navigation_flutter depend on the Google Maps SDK, mismatched SDK versions could potentially cause conflicts. To mitigate this, the google_navigation_flutter package also includes a GoogleMapsMapView widget (documentation) that supports most of the features of google_maps_flutter. I recommend trying this GoogleMapsMapView instead of google_maps_flutter to rule out any potential SDK conflicts.

In your original issue you were using version google_navigation_flutter: ^0.3.0 but pubspec file is pointing to google_navigation_flutter: ^0.4.0. I bet this issue is visible with both version?

I would like to see if communication works without google_maps_flutter to make sure it does not cause any conflicts.

I tried to reproduce the issue without luck yet.

The messaging channel is initialized when createNavigationSession is called here:


Internally, this method is triggered during navigation session initialization through initializeNavigationSession (which you should call on navigation initialization).

Could you make sure that this ensureSessionAPISetUp is called on your implemententaion with breakpoints.

Turn-by-Turn events (NavEvents) can be listened only with after navigation session initialized, so for this reason the messaging channel should have been initialized when navInfo events are listened and processed. Reason why message channel is not properly initialized is still open.

As a workaround it is possible to (re)initialize the api without calling createNavigationSession with following code:

  if (Platform.isIOS) {
    (GoogleMapsNavigationPlatform.instance as GoogleMapsNavigationIOS)
        .ensureSessionAPISetUp();
  }

@liatprasa
Copy link

HI, about iOS issue -
We have made the changes mentioned above: used this GoogleMapsMapView instead of google_maps_flutter
and (re)initialize the api without calling createNavigationSession
but still have the same result -
the app fails on channel communication. Specifically, the response in the onNavInfo function is nil, leading to a failure in the completion handler.

Flutter version 3.24.3, stable channel
sonama 14.5, intel
google_navigation_flutter: ^0.4.0

from messages.g.swift
/// Turn-by-Turn navigation events.

func onNavInfo(navInfo navInfoArg: NavInfoDto,
completion: @escaping (Result<Void, FlutterError>) -> Void) {
let channelName =
"dev.flutter.pigeon.google_navigation_flutter.NavigationSessionEventApi.onNavInfo"
let channel = FlutterBasicMessageChannel(
name: channelName,
binaryMessenger: binaryMessenger,
codec: codec
)
channel.sendMessage([navInfoArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
// The code goes here and the response is nil
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants