Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter file write fails with Permission denied (errno = 13)

ErrorOS Error: Permission denied, errno = 13

Short answer

Errno 13 means the operating system refused the file operation. In Flutter it usually means the path is outside the folders your app owns. Build the path from path_provider, such as the documents directory, instead of a hard-coded one. On macOS, the sandbox may also need a file entitlement.

  • Applies to Flutter 3.3x stable, Dart 3.x, path_provider, Android 10 to 15, macOS
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the exact path the failing call uses, and compare it with the app documents directory.

    final dir = await getApplicationDocumentsDirectory();
    print('app dir: ${dir.path}');
    print('writing to: $yourPath');
  2. 2Match what you see, then jump to its fix

    1. 1The path is a hard-coded folder such as /storage/emulated/0/... or the root of the deviceThe path is outside the app's own storageFix
    2. 2The file access fails only in the macOS app, and the app uses a plugin such as file_selectorThe macOS App Sandbox blocks the file accessFix

What does the error look like?

  • OS Error: Permission denied, errno = 13

Cause 1 of 2

The path is outside the app's own storage

1Check

Android gives each app a private area that needs no permission. Apps that target Android 10 (API 29) or higher get scoped access to external storage by default, so writing to other locations is refused.

grep -rn "File(\|Directory(" lib/

2Fix

Build the path from path_provider's application documents directory, as the Flutter file recipe does.

import 'dart:io';
import 'package:path_provider/path_provider.dart';

final dir = await getApplicationDocumentsDirectory();
final file = File('${dir.path}/notes.txt');
await file.writeAsString('hello');

3Verify

Run the write again and read the file back.

print(await file.readAsString());

Confirmed by docs.flutter.dev

Did this fix it?

Cause 2 of 2

The macOS App Sandbox blocks the file access

1Check

macOS builds are sandboxed by default. Reading files the user picks, for example through the file_selector plugin, needs a user-selected entitlement in both entitlements files.

cat macos/Runner/DebugProfile.entitlements macos/Runner/Release.entitlements

2Fix

Add the matching entitlement to both files, with identical changes in each, then rebuild.

<key>com.apple.security.files.user-selected.read-write</key>
<true/>

3Verify

Rebuild the macOS app and repeat the file operation.

flutter run -d macos

Confirmed by docs.flutter.dev

Did this fix it?

How do I stop it coming back?

  • Never hard-code storage paths. Ask path_provider for the directory.
  • Use the share or save-file picker when the user needs the file outside your app.
  • On macOS, edit both entitlements files by hand and keep them in step.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Google Play says the app does not support 16 KB memory pages

check_elf_alignment.sh reports UNALIGNED for a library under lib/arm64-v8a

Google Play requires apps that target Android 15 or higher and ship native .so libraries to run on devices with 16 KB memory pages; from 1 February 2027 it will block updates that do not.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.