Skip to content

Flutter 3.50.0 cannot load assets with filenames starting with a dot #196444

Closed

Description

@ornellix

Steps to reproduce

  1. Create a new Flutter project using Flutter 3.50.0.
  2. Add the latest flutter_dotenv dependency.
  3. Create a file named .env in the project root.
  4. Add it to pubspec.yaml:
flutter:
  assets:
    - .env
  1. Load it from main.dart:
import 'package:flutter_dotenv/flutter_dotenv.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await dotenv.load(fileName: '.env');

  runApp(const MyApp());
}

Expected results

The .env file should be available as a Flutter asset and dotenv.load() should successfully load it.

Actual results

Flutter cannot find the asset and flutter_dotenv throws:

FileNotFoundError: Environment file ".env" not found. Ensure the file exists and is listed under assets in pubspec.yaml.

The important detail is that the same setup works when the file is renamed from .env to env (without the leading dot).
I also tested other filenames starting with a dot, and they show the same behavior.

Code sample

Code sample

main.dart

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await dotenv.load(fileName: '.env');

  runApp(const MyApp());
}

Pubspec.yaml

flutter:
  assets:
    - .env

And then put a .env file in your project

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.50.0, on Microsoft Windows [Versione 10.0.26100.9711], locale it-IT) [533ms]
    • Flutter version 3.50.0 on channel stable at C:\Users\Utente\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ab2912035e (3 days ago), 2026-11-09 08:50:21 -0800
    • Engine revision 371f77202a
    • Dart version 3.14.0
    • DevTools version 2.61.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager,
      omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[√] Windows Version (Windows 11 or higher, 24H2, 2009) [1.067ms]

[√] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1) [695ms]
    • Android SDK at C:\Users\Utente\AppData\Local\Android\sdk
    • Emulator version 37.2.13.0 (build_id 16740729) (CL:N/A)
    • Platform android-37.1, build-tools 36.1.0-rc1
    • Java binary at: C:\Users\Utente\AppData\Local\Programs\Eclipse Adoptium\jdk-21.0.12.8-hotspot\bin\java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Temurin-21.0.12+8 (build 21.0.12+8-LTS)
    • All Android licenses accepted.

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

[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.14.19) [171ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
    • Visual Studio Professional 2022 version 17.14.36623.8
    • Windows 10 SDK version 10.0.26100.0

[√] Connected device (4 available) [1.123ms]
    • sdk gphone16k x86 64 (mobile) • emulator-5554 • android-x64    • Android 17 (API 37) (emulator)
    • Windows (desktop)             • windows       • windows-x64    • Microsoft Windows [Versione 10.0.26100.9711]
    • Chrome (web)                  • chrome        • web-javascript • Google Chrome 156.0.8078.79
    • Edge (web)                    • edge          • web-javascript • Microsoft Edge 155.0.4283.45

[√] Network resources [589ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. added
    in triage
    waiting for response
    and removed
    in triage
    on Nov 12, 2026
  2. mbcorona commented on Nov 12, 2026

    @mbcorona
    Member

    Thanks for the report @ornellix.

    I couldn’t reproduce this on Flutter 3.50.0 on macOS: a .env file listed under assets in pubspec.yaml loads correctly with rootBundle.loadString('.env').

    To narrow it down, could you tell us which device you ran on (Android emulator, Windows or web), and try the same app without flutter_dotenv, loading the file directly with await rootBundle.loadString('.env') after WidgetsFlutterBinding.ensureInitialized()? If that fails too, please share the output of flutter run -v and the error message.

  3. joellemd commented on Nov 12, 2026

    @joellemd
    Contributor

    I think this is Android-only, which would explain why it doesn't reproduce on macOS @mbcorona

    Since 3.50, the Flutter Gradle plugin adds flutter_assets/ to the app as a generated assets source directory (#192488). Before that, it copied them into AGP's merged-assets output. AGP filters assets source directories with androidResources.ignoreAssetsPattern. The default is !.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~, so any file starting with . is dropped from the APK. That matches what @ornellix sees: .env fails and env works. Asset folders whose names start with _ should be dropped the same way.

    @ornellix, if you're running on the Android emulator, this workaround in android/app/build.gradle.kts should unblock you (it also stops filtering dotfiles in src/main/assets):

    android {
        androidResources {
            ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
        }
    }
    
  4. added
    in triage
    platform-android
    c: regression
    t: gradle
    a: assets
    found in release: 3.5
    workaround available
    found in release: 3.47
    and removed
    in triage
    on Nov 12, 2026
  5. 3 remaining items

  6. mbcorona commented on Nov 12, 2026

    @mbcorona
    Member

    Thanks @joellemd for the analysis, the workaround and the fix.

    Reproduced on Flutter 3.50.0 with an Android emulator: a .env asset fails to load with rootBundle.loadString('.env'), while the same app works on macOS. Confirmed in source as a 3.50 regression: the Flutter Gradle plugin in 3.47.9 does not register the Flutter assets as an assets source directory, while 3.50.0 does, so AGP’s default ignoreAssetsPattern drops dotfiles and _-prefixed directories. Datadog’s dd-sdk-flutter hit the same problem. PR #196465 is up with a fix.

    Routing to the Android team.

  7. mboetger commented on Nov 12, 2026

    @mboetger
    Contributor
  8. self-assigned this
    on Nov 12, 2026
  9. added
    found in release: 3.50
    on Nov 12, 2026
  10. added a commit that references this issue on Nov 16, 2026
    6b90832
  11. S-Man42 commented on Nov 17, 2026

    @S-Man42

    I have issues with directories starting with an underscore. Same issue?

  12. reidbaker commented on Nov 17, 2026

    @reidbaker
    Member

    @S-Man42 yes it is the same issue. Flutter master has the fix and I have cherry pick prs up for 3.51 beta and 3.50.1 stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: assetsc: regressionfound in release: 3.47found in release: 3.5found in release: 3.50platform-androidt: gradleteam-androidtoolworkaround available

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions