llfbandit / dio_cache_interceptor

Dio HTTP cache interceptor with multiple stores respecting HTTP directives (ETag, Last-Modified, Cache-Control) with options.
https://pub.dev/packages/dio_cache_interceptor
120 stars 70 forks source link

PlatformDispatcher.instance.onError: PathAccessException: Creation failed #131

Closed vtisnado closed 1 year ago

vtisnado commented 1 year ago

Hi guys,

I'm getting the following error and I can't find how to fix it. In Android the cache it's not working, but on iOS breaks completely the app. Any clue what can be wrong?

PathAccessException: Creation failed, path = '/var/mobile/Containers/Data/Application/6CB0330F-A495-58C4-493A' (OS Error: Operation not permitted, errno = 1)
flutter: 
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:114:9)
<asynchronous suspension>
#2      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:34:7)
<asynchronous suspension>
#3      HiveImpl._openBox (package:hive/src/hive_impl.dart:101:21)
<asynchronous suspension>
#4      HiveImpl.openLazyBox (package:hive/src/hive_impl.dart:160:12)
<asynchronous suspension>
#5      HiveCacheStore._openBox (package:dio_cache_interceptor_hive_store/src/store/dio_cache_interceptor_hive_store.dart:143:14)
<asynchronous suspension>
#6      HiveCacheStore.clean (package:dio_cache_interceptor_hive_store/src/store/dio_cache_interceptor_hive_store.dart:44:17)
<asynchronous suspension>

The result of flutter doctor:

[✓] Flutter (Channel stable, 3.10.2, on macOS 13.2.1 22D68 darwin-arm64, locale en-PA)
    • Flutter version 3.10.2 on channel stable at /Users/USER/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9cd3d0d9ff (8 weeks ago), 2023-05-23 20:57:28 -0700
    • Engine revision 90fa3ae28f
    • Dart version 3.0.2
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/USER/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2021.3)
    • 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.13+0-b1751.21-8125866)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.2.1 22D68 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 115.0.5790.98

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

• No issues found!
vtisnado commented 1 year ago

Is anyone else facing this issue?

llfbandit commented 1 year ago

The exception is pretty clear to me, your app has no access/permission to the directory you set up.

vtisnado commented 1 year ago

The exception is pretty clear to me, your app has no access/permission to the directory you set up.

I thought exactly the same and tried to add more permissions to the app, but didn't worked.

Couple things to take in mind:

  1. App was using Hive without any special permission. The error start happening after an update I made after the release with this library.
  2. The app works fine when I remove dio_cache_interceptor.
  3. Yo mentioned that the app "has no access/permission", could you share any documentation about this? I could not find any working solution in the pub.dev page, Github or Stackoverflow.

I deeply appreciate if you could guide me, since I have weeks trying without luck.

llfbandit commented 1 year ago

If you already are using Hive in your app, set the directory parameter to null. This will avoid to call internally Hive.init. This may be the cause of the issue then.

vtisnado commented 1 year ago

Thank you @llfbandit ! This fixed the issue in Android and iOS! I would never figure it out.