[path_provider] Running in release mode throws a MissingPluginException

I was trying to build my Flutter project in release mode for Android when the application crashed with an exception. (Debug mode works fine however)

Launching lib\main.dart on motorola one in release mode...
Running Gradle task 'assembleRelease'...
√ Built build\app\outputs\flutter-apk\app-release.apk (8.0MB).
E/flutter (22760): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)
E/flutter (22760): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156)
E/flutter (22760): <asynchronous suspension>
E/flutter (22760): #1      getApplicationDocumentsDirectory (package:path_provider/path_provider.dart:139)

I am using path_provider: 2.0.1

Steps to Reproduce

  1. Run flutter create bug.
  2. Update main.dart with an import for path_provider & a call to getApplicationDocumentsDirectory()
import 'package:path_provider/path_provider.dart';

void main() async { 
  // This should fail.
  await getApplicationDocumentsDirectory();

  // The widget itself is irrelevant.
  1. The exception occurs when running the app.

Expected results:
The app runs.

Actual results:
The app crashes.

flutter doctor -v

[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19041.867], locale nl-BE)
    • Flutter version 2.0.2 at E:\Flutter\flutter
    • Framework revision 8962f6dc68 (7 days ago), 2021-03-11 13:22:20 -0800
    • Engine revision 5d8bf811b3
    • Dart version 2.12.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at E:\Android\Sdk
    • Platform android-30, build-tools 30.0.0
    • ANDROID_HOME = E:\Android\Sdk
    • Java binary at: E:\Android\AndroidStudio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0)
    • Android Studio at E:\Android\AndroidStudio
    • Flutter plugin can be installed from:
    • Dart plugin can be installed from:
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (3 available)
    • motorola one (mobile) • ZL5228NFL7 • android-arm64  • Android 10 (API 29)
    • Chrome (web)          • chrome     • web-javascript • Google Chrome 88.0.4324.182
    • Edge (web)            • edge       • web-javascript • Microsoft Edge 88.0.705.68

• No issues found!

1 possible answer(s) on “[path_provider] Running in release mode throws a MissingPluginException

  1. @pedromassangocode I realized I have an SDK constraint of >= 2.9.0 <3.0.0 in my project. I tested the code sample with NNBD enabled and it worked. Closing the issue. I’ll have to migrate my dependencies and codebase to NNBD, that’ll work out on my end.