flutter_dotenv icon indicating copy to clipboard operation
flutter_dotenv copied to clipboard

using flutter dotenv for build release

Open hnexokonkwo opened this issue 5 years ago • 21 comments

How can I use this library to build releases for android and ios? the environment variable does not seem to work after building apk release version

hnexokonkwo avatar Sep 28 '20 14:09 hnexokonkwo

Can you confirm the .env file is included in the bundle? Typically you will add the .env file with the desired environment config as part of the build.

java-james avatar Jan 15 '21 00:01 java-james

same thing seems to happen with flutter build web. the .env file is present in build/web/assets/.env But as per the docs, .env should be declared in ./ in pubspec.yaml:

assets:
 - .env

not sure if its the problem though

arnaudelub avatar Mar 16 '21 12:03 arnaudelub

same issue. I also tried to add the env file into the assets directory.

fc-ds avatar Apr 02 '21 09:04 fc-ds

I've got the same issue

gelintonx avatar Apr 07 '21 20:04 gelintonx

This is happening to me too unfortunately. Everything goes fine when I run in debug mode, but when I run the web build release then the error happens!

Azzeccagarbugli avatar Apr 13 '21 19:04 Azzeccagarbugli

I notice that I had a unrelated bug. I just added the file into the assets directory and include the file in the pubspec.yaml. Worked

fc-ds avatar Apr 14 '21 09:04 fc-ds

i tried dropping .env in /assets, no luck.

edcmex avatar Apr 26 '21 14:04 edcmex

Attempted to deploy web build version on surge, the provided example with .env file in assets folder works fine: web version. Ensure that - the .env file location, - the fileName parameter in dotenv.load() and - asset filepath in pubspec.yaml, are all the same.

ngxingyu avatar Apr 26 '21 15:04 ngxingyu

During the release for iOS, the app I work on was crashing on startup on a physical device with iOS 14.6 (it was working just fine on the simulator). The application was already in production for Android.

I removed all code related to the package before iOS release build and the app did not crash anymore. Seems like the .env file was not being created.

NOTE: I was getting the variables using env['VARIABLE_NAME'] within the code.

rairongf avatar Jul 22 '21 19:07 rairongf

removed the dot from the start of file name resolve for me. from ".env" to "env"

andredealmei avatar Oct 28 '21 23:10 andredealmei

removed the dot from the start of file name resolve for me. from ".env" to "env"

This should be included in documentation. The documentation and the default parameter both suggest to name the file .env but the naming causes issue in flutter web

shatanikmahanty avatar Feb 04 '22 09:02 shatanikmahanty

Using the above suggestion does not resolve issue of the package not working on release mode for iOS or Android.

lbk9 avatar Feb 16 '22 12:02 lbk9

I have it working while running in dev and profile, but it doesnt work in release mode.

Akisan98 avatar Apr 17 '22 13:04 Akisan98

same issue, works fine on debug. On android release it does not work at all.

lcsvcn avatar Apr 30 '22 23:04 lcsvcn

Seems working on the last version 5.0.2 with Flutter 3.0.1

martinfrouin avatar Jun 09 '22 06:06 martinfrouin

Check if you have added
<uses-permission android:name="android.permission.INTERNET" /> in your Androidmanifest.xml

teamnadanzz avatar Sep 19 '22 18:09 teamnadanzz

Check if you have added <uses-permission android:name="android.permission.INTERNET" /> in your Androidmanifest.xml

It was cause for me...

auaicn avatar May 31 '23 08:05 auaicn

removed the dot from the start of file name resolve for me. from ".env" to "env"

It worked ! Thanks a lot!

shroot91 avatar Sep 11 '23 14:09 shroot91

removed the dot from the start of file name resolve for me. from ".env" to "env"

I had a similar issue building a Flutter module. It work fine for iOS, but it was not working for Android. This solved the issue.

edzzn avatar May 13 '24 22:05 edzzn

thank you so much! this saved my life.

KanhaKorgaonkar avatar Jul 13 '24 11:07 KanhaKorgaonkar

removed the dot from the start of file name resolve for me. from ".env" to "env"

This solve my issue. Some systems treat files that start with a "dot" in a special way. This is the case with github actions, for example.

xamiell avatar Sep 26 '24 23:09 xamiell