objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Add-to-app on iOS: crash of PathProvider (PlatformException) #552

Closed kundankuldeep closed 8 months ago

kundankuldeep commented 9 months ago

Overview: Building a framework with flutter to integrate in existing native IOS Application. The framework consisting of Objectbox for some data persistence, which is not getting initialised when run as framework, giving out channel-error

Basic info:

[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/kundankumar/Library/Android/sdk ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.12.1

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1) • Android Studio at /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 11.0.15+0-b2043.56-8887301)

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

[✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 13.4.1 22F770820d darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.170

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

! Doctor found issues in 1 category.

Steps to reproduce

  1. Build an add to app flutter module
  2. Create a framework from that module for IOS
  3. Add that framework to Native IOS application
  4. Run the IOS application, object box will not working
  5. It is creating the following error
unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      PathProviderApi.getDirectoryPath (package:path_provider_foundation/messages.g.dart:42)
<asynchronous suspension>
#1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:121)
<asynchronous suspension>
#2      ObjectBox.create (package:flutter_lib/objectBox/ObjectBoxManager.dart:28)

For reference - https://docs.flutter.dev/add-to-app

Expected behavior

The Object box should work fine as its working when running directly from flutter to device

Code

Logs, stack traces

_2023-08-17 17:41:59.439466+0530 ***********[1927:1023140] flutter: ObjectBoxIssue: message: [0]
2023-08-17 17:41:59.442221+0530 ***********[1927:1023140] flutter: Flutter: setThemeMode-> Brightness.light
2023-08-17 17:41:59.446920+0530 ***********[1927:1023140] flutter: Flutter: setThemeMode-> Brightness.light
2023-08-17 17:41:59.447347+0530 ***********[1927:1023140] flutter: ObjectBoxIssue: getDirectoryPath: arg_type: DirectoryType.applicationDocuments
2023-08-17 17:41:59.447382+0530 ***********[1927:1023140] flutter: ObjectBoxIssue: message: [0]
2023-08-17 17:41:59.447824+0530 ***********[1927:1022736] Flutter : response ACTION_DEVICE_INFO - nil)
2023-08-17 17:41:59.448239+0530 ***********[1927:1023140] flutter: ObjectBoxIssue: getDirectoryPath: replyList: null
2023-08-17 17:41:59.449447+0530 ***********[1927:1023140] [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      PathProviderApi.getDirectoryPath (package:path_provider_foundation/messages.g.dart:42)
<asynchronous suspension>
#1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:121)
<asynchronous suspension>
#2      ObjectBox.create (package:flutter_lib/objectBox/ObjectBoxManager.dart:28)
<asynchronous suspension>
#3      initObjectBox (package:flutter_lib/main.dart:66)
<asynchronous suspension>
Push Token:579793f10d2722900611b45ba7ad8ae47712a9af907edbc08ad8402edfe47ae6
2023-08-17 17:41:59.452891+0530 ***********[1927:1023140] flutter: ObjectBoxIssue: getDirectoryPath: replyList: null
2023-08-17 17:41:59.453239+0530 ***********[1927:1023140] [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      PathProviderApi.getDirectoryPath (package:path_provider_foundation/messages.g.dart:42)
<asynchronous suspension>
#1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:121)
<asynchronous suspension>
#2      ObjectBox.create (package:flutter_lib/objectBox/ObjectBoxManager.dart:28)
<asynchronous suspension>
#3      initObjectBox (package:flutter_lib/main.dart:66)
<asynchronous suspension>
#4      getDlManager (package:flutter_lib/main.dart:52)
<asynchronous suspension>
#5      _ApplicationState.initEventManager (package:flutter_lib/main.dart:144)
<asynchronous suspension>_

Additional context

greenrobot-team commented 9 months ago

This crash originates in the path_provider package, not objectbox:

2023-08-17 17:41:59.449447+0530 Jeevansathi[1927:1023140] [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      PathProviderApi.getDirectoryPath (package:path_provider_foundation/messages.g.dart:42)
<asynchronous suspension>
#1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:121)
<asynchronous suspension>
#2      ObjectBox.create (package:flutter_lib/objectBox/ObjectBoxManager.dart:28)

After googling a bit there does not appear to be a single cause (might be permissions, might be outdated versions). So please have a look yourself. If you solve this we would love to hear your solution in case other users are affected by this.

kundankuldeep commented 9 months ago

Thanks @greenrobot-team, Debugging the same!! Will update the solution when we found solution to this.

github-actions[bot] commented 8 months ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.

kundankuldeep commented 8 months ago

This Issue currently active on path provider, and no solution is provided from the developer yet.

but We have managed to resolve this issue by getting the path from native IOS Platform through channel while creating the box.

Thanks.