Repository navigation
Open
Labels
a: assetsPackaging, accessing, or using assetsPackaging, accessing, or using assetsc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.47Found to occur in 3.47Found to occur in 3.47found in release: 3.5Found to occur in 3.5Found to occur in 3.5found in release: 3.50Found to occur in 3.50Found to occur in 3.50platform-androidAndroid applications specificallyAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.workaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Description
Steps to reproduce
- Create a new Flutter project using Flutter 3.50.0.
- Add the latest flutter_dotenv dependency.
- Create a file named .env in the project root.
- Add it to pubspec.yaml:
flutter:
assets:
- .env
- 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:
- .envAnd 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!Metadata
Metadata
Assignees
Labels
a: assetsPackaging, accessing, or using assetsPackaging, accessing, or using assetsc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.47Found to occur in 3.47Found to occur in 3.47found in release: 3.5Found to occur in 3.5Found to occur in 3.5found in release: 3.50Found to occur in 3.50Found to occur in 3.50platform-androidAndroid applications specificallyAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.workaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Activity
mbcorona commentedon Nov 12, 2026
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.
joellemd commentedon Nov 12, 2026
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):
chore(ci): Rename generated .env to dd.env
mbcorona commentedon Nov 12, 2026
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.
mboetger commentedon Nov 12, 2026
@reidbaker - fyi
chore: use latest Flutter in CI and mark the .env override as tempora…
fix(example): temporary workaround for .env asset dropped on Android …
Temporary workaround for .env asset dropped on Android with Flutter 3…
chore: upgrade to Flutter 3.50 + AGP 9 built-in Kotlin